develooper Front page | perl.libwww | Postings from December 2000

Re: Parse and save to file

Thread Previous | Thread Next
From:
merlyn
Date:
December 17, 2000 11:03
Subject:
Re: Parse and save to file
Message ID:
m18zpeeupj.fsf@halfdome.holdit.com
>>>>> "Ivan" == Ivan C Myrvold <ivan@myrvold.org> writes:

Ivan> I want to parse a web page, and have this command in my program:
Ivan> $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])});

Ivan> But I also want this web page on file, so the next line is:

Ivan> $res = $ua->request(HTTP::Request->new(GET => $url), 'tvschedule.html');

Ivan> Can I combine these two into one, so I do not need to GET the web page two times?

Just make the callback also write the file:

    my $response = do {
      my $handle = IO::File->new(">tvschedule.html");
      $ua->request(HTTP::Request->new(GET => $url), sub {
        print $handle $_[0];
        $p->parse($_[0]);
      });
    };

Hmm.  I should think of a use for that and put it into a column.
Thanks for the idea. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About