Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl equivalent of this script?

Reply
Thread Tools

Perl equivalent of this script?

 
 
george.varsamopoulos@gmail.com
Guest
Posts: n/a
 
      07-16-2006
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.

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-16-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:

> 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;


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
george.varsamopoulos@gmail.com
Guest
Posts: n/a
 
      07-17-2006

Tad McClellan wrote:
> (E-Mail Removed) <(E-Mail Removed)> wrote:
>
> > 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?
>


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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      07-17-2006
(E-Mail Removed) wrote:
> Tad McClellan wrote:
> > You didn't even look in the Perl FAQ? That's not very nice.


> 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

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-17-2006
Paul Lalli <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>> Tad McClellan wrote:
>> > You didn't even look in the Perl FAQ? That's not very nice.

>
>> I tried to "google" for it,



> 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.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      07-17-2006
On 17 Jul 2006, (E-Mail Removed) wrote:

Paul Lalli <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>> Tad McClellan wrote:
>>>> You didn't even look in the Perl FAQ? That's not very nice.

>>
>>> I tried to "google" for it,

>
>> 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.


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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-17-2006
Ted Zlatanov <(E-Mail Removed)> wrote:
> On 17 Jul 2006, (E-Mail Removed) wrote:
>
> Paul Lalli <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> Tad McClellan wrote:
>>>>> You didn't even look in the Perl FAQ? That's not very nice.
>>>
>>>> I tried to "google" for it,

>>
>>> 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.

>
> 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.

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.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 04-04-2011 10:00 PM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments