Perl equivalent of this script?

  • Thread starter george.varsamopoulos
  • Start date
G

george.varsamopoulos

I have a collection of perl scripts to manipulate HTML documents and
extract information.
However, i didn't find any short and easy way in Perl to download a
HTML file and save it locally.
For that reason I use the following php script:

<?php
$url = "http://yes.yes.yes/?arg=".$argv[1];
if (($ff = fopen($url, "r"))==NULL) exit();
while (!feof($ff)){
$line = fgets($ff,512);
printf("%s", $line);
}
fclose($ff);
?>

The ease with php is that I can fopen a URL, read it and save it (or
print it to stdout)
like a regular file.

the QUESTION is:
## Is there a short Perl script to replace this PHP script? ##


Any suggestions are welcome
-- George

P.S. I am mainly asking because this is the only part of the script
collection not written in Perl;
using a perl version I could compact the scripts into one.
 
T

Tad McClellan

i didn't find


You didn't even look in the Perl FAQ? That's not very nice.

perldoc -q HTML

How do I fetch an HTML file?

<?php
$url = "http://yes.yes.yes/?arg=".$argv[1];
if (($ff = fopen($url, "r"))==NULL) exit();
while (!feof($ff)){
$line = fgets($ff,512);
printf("%s", $line);
}
fclose($ff);
?>
## Is there a short Perl script to replace this PHP script? ##


use LWP::Simple;
my $url = 'http://www.perl.org/';
exit unless my $html = get $url;
print $html;
 
G

george.varsamopoulos

Tad said:
You didn't even look in the Perl FAQ? That's not very nice.

perldoc -q HTML

How do I fetch an HTML file?

I tried to "google" for it, believing that it would return hits from
the FAQ as well. Apparently, wording it "how to..." and not "how do
I..." did not hit the FAQ. I found some solutions, however not as
concise as the ones in the FAQ.

All in all, thank you for your help, and I appreciate your feedback.

--George
 
P

Paul Lalli

I tried to "google" for it, believing that it would return hits from
the FAQ as well. Apparently, wording it "how to..." and not "how do
I..." did not hit the FAQ. I found some solutions, however not as
concise as the ones in the FAQ.

Allow me to suggest that when looking for assistance with Perl, Google
be your *last* resort, not your first. The PerlFAQ and other
documentation have their own web-based interface if you dislike the
command line or just like searching online. Have a look at
http://perldoc.perl.org

Paul Lalli
 
T

Tad McClellan

Paul Lalli said:
Allow me to suggest that when looking for assistance with Perl, Google
be your *last* resort, not your first.


Allow me to suggest that when looking for assistance with Perl,
posting to a Usenet newgroup be your last resort. :)
 
T

Ted Zlatanov

Allow me to suggest that when looking for assistance with Perl,
posting to a Usenet newgroup be your last resort. :)

I don't think you worded that well, Tad. Are you saying the OP should
buy a book on Perl, look at the Perl source code, e-mail Larry Wall,
etc. before he asks for help here? I think most people on the
newsgroup wouldn't call it a last resort.

Ted
 
T

Tad McClellan

Ted Zlatanov said:
I don't think you worded that well, Tad.


I was trying to say that Google is not a last resort, since it
should come before posting to Usenet.

Are you saying the OP should
buy a book on Perl, look at the Perl source code, e-mail Larry Wall,
etc. before he asks for help here?


No. Let me try it again:

Allow me to suggest that when looking for assistance with Perl,
posting to a Usenet newgroup be something you do only after
searching the std docs and a Usenet archive.

That is a paraphrasing of a Perl Problem Resolution Checklist
that I post from time to time.

<... time passes ...>

Golly! It looks like I haven't posted it since 2001,
so here it is again:


----------------------------------
Perl problem resolution checklist:
----------------------------------

1) check the Perl FAQs

(word search with "perldoc -q". Or better, find where the
*.pod's are on your system, and word search (grep) the
entire contents of the files)

2) expand the above to _all_ of the standard *.pod files.

3) check a Usenet archive such as:

http://groups.google.com/advanced_group_search

4) check books and websites (this step is optional)

5) write a Usenet article, but don't post it yet!

5a) make a small and complete (including data) program that
people can execute that shows your problem.

5b) state how the program's output is not what you want. Describe
what you want.

5c) repeat steps 1-4 using search terms taken from your description
of the problem or your Subject header (try some synonyms for
the terms also)

6) Give up on a quick answer. Post to Usenet for a slow answer.

7) wait hours/days/forever for followups with answers rather than
than the 5 or 10 minutes it would have taken if steps 1-3
had worked.

8) Wonder at the quality of the answers given, rather than know
it is a peer-reviewed, validated answer if steps 1-2 had worked.

9) Repeat steps 1-3 many times for many problems. You will seldom
get past step 3, and even less often get past step 5a.

10) Now that you know so much, go *answer* some questions on Usenet :)


-----

To help with 1 and 2 above, I make "headlines" files to grep in,
because sometimes there is Too Much Information when grepping
the entire bodies:

cd /an/INC/dir/pod/

grep '^=' perlfaq[1-9].pod >faq.heads

grep '^=' *.pod >all.heads


I think most people on the
newsgroup wouldn't call it a last resort.


It is certainly a resort that comes after "search Google" though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top