>>>>> "Ivan" == Ivan C Myrvold <[EMAIL PROTECTED]> 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
<[EMAIL PROTECTED]> <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!

Reply via email to