![]() |
Perl equiv to PHP file() ?
Does Perl have an equivalent to the PHP function file()? file() reads a
file into an array. More importantly for me, you can pass a URL to file(), and it will read into the array the HTML output of that file as served through HTTP: $output = file(''http://www.mysite.com/test.pl'') This will read the HTML output of the test.pl executable and put each line of it into a successive element of the $output array. (In PHP, $ designates any variable, including an array -- it does not use @ or % to distinguish variable types.) It would be very helpful to me if I could find a Perl equivalent to PHP's file(url). Thanks! Amittai Aviram |
Re: Perl equiv to PHP file() ?
Amittai Aviram wrote:
> Does Perl have an equivalent to the PHP function file()? file() > reads a file into an array. More importantly for me, you can pass > a URL to file(), and it will read into the array the HTML output of > that file as served through HTTP: > > $output = file(''http://www.mysite.com/test.pl'') > > This will read the HTML output of the test.pl executable and put > each line of it into a successive element of the $output array. use LWP::Simple; @output = split /\n/, get('http://www.mysite.com/test.pl'); http://search.cpan.org/author/GAAS/l.../LWP/Simple.pm -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
Re: Perl equiv to PHP file() ?
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message news:bhr4r8$29agi$1@ID-184292.news.uni-berlin.de... > Amittai Aviram wrote: > > Does Perl have an equivalent to the PHP function file()? file() > > reads a file into an array. More importantly for me, you can pass > > a URL to file(), and it will read into the array the HTML output of > > that file as served through HTTP: > > > > $output = file(''http://www.mysite.com/test.pl'') > > > > This will read the HTML output of the test.pl executable and put > > each line of it into a successive element of the $output array. > > use LWP::Simple; > @output = split /\n/, get('http://www.mysite.com/test.pl'); > > http://search.cpan.org/author/GAAS/l.../LWP/Simple.pm > GREAT! Thank you so much, Gunnar! One follow-up question ... The getstore($url, $file) actually looks exactly like what I want, since it gets the HTML document and "stores it in the file." But I'm not clear about the code context. Should you first define $file as a file handle? Do you need to open the file first before calling getstore? And then close it afterwards? This may seem obvious to many here, but the documentation left it unclear and perhaps the info would be helpful to other newbies, as well as to me. Thanks again for the help. Amittai |
Re: Perl equiv to PHP file() ?
Amittai Aviram <amittai@amittai.com> wrote:
> you can pass a URL to file(), > and it will read into the array the HTML output of that file as served > through HTTP: Your Question is Asked Frequently: perldoc -q HTML How do I fetch an HTML file? -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas |
Re: Perl equiv to PHP file() ?
Amittai Aviram wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message > news:bhr4r8$29agi$1@ID-184292.news.uni-berlin.de... > >> use LWP::Simple; >> @output = split /\n/, get('http://www.mysite.com/test.pl'); >> >> http://search.cpan.org/author/GAAS/l.../LWP/Simple.pm > > GREAT! Thank you so much, Gunnar! One follow-up question ... > > The getstore($url, $file) actually looks exactly like what I want, > since it gets the HTML document and "stores it in the file." Well, you said array... > But I'm not clear about the code context. Should you first define > $file as a file handle? Do you need to open the file first before > calling getstore? And then close it afterwards? To be able to give you a reliable answer to that question, I did what you should have done before asking: I tested. ;-) $file is just the path to the file, and you don't need to open/close it separately. This should do it: use LWP::Simple; getstore('http://www.mysite.com/test.pl', $file); -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
| All times are GMT. The time now is 05:06 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.