Perl equivalent of this script?

Discussion in 'Perl Misc' started by george.varsamopoulos@gmail.com, Jul 16, 2006.

  1. Guest

    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.
    , Jul 16, 2006
    #1
    1. Advertising

  2. <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 16, 2006
    #2
    1. Advertising

  3. Guest

    Tad McClellan wrote:
    > <> 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
    , Jul 17, 2006
    #3
  4. Paul Lalli Guest

    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
    Paul Lalli, Jul 17, 2006
    #4
  5. Paul Lalli <> wrote:
    > 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 17, 2006
    #5
  6. Ted Zlatanov Guest

    On 17 Jul 2006, wrote:

    Paul Lalli <> wrote:
    > 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
    Ted Zlatanov, Jul 17, 2006
    #6
  7. Perl Problem Resolution Checklist (was Re: Perl equivalent of this script?)

    Ted Zlatanov <> wrote:
    > On 17 Jul 2006, wrote:
    >
    > Paul Lalli <> wrote:
    >> 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.

    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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 17, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,518
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,793
  3. pj
    Replies:
    3
    Views:
    284
  4. Mike

    Perl equivalent to unix script

    Mike, Oct 30, 2006, in forum: Perl Misc
    Replies:
    11
    Views:
    408
    Peter J. Holzer
    Nov 3, 2006
  5. Generic Usenet Account

    Perl equivalent of simple awk script

    Generic Usenet Account, Nov 12, 2008, in forum: Perl Misc
    Replies:
    5
    Views:
    177
Loading...

Share This Page