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

Re: Parse and save to file

Thread Previous | Thread Next
December 17, 2000 11:03
Re: Parse and save to file
Message ID:
>>>>> "Ivan" == Ivan C Myrvold <> 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];

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
<> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training!

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About