suaveant has asked for the wisdom of the Perl Monks concerning the following question:

I am pulling data from a cgi that returns XML and requires authentication. I want to use LWP to get the data but I'd rather pass the XML parser an IO handle than read the entire thing into memory. I have been looking around in the copious LWP docs and all I see are the options to pull all the data or to have a callback hand out chunks.

Is there an easy way to just get an IO handle?

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Can you get LWP data in a stream?
by kyle (Abbot) on Dec 05, 2007 at 16:25 UTC

    I suspect you'll have to use the callback to take chunks from LWP and feed them to your XML parser. You can use open to fork with a pipe to the child and feed the data through that. Here's a sketch:

    my $pid = open my $child_fh, '|-' die "Can't fork: $!" if ! defined $pid; if ( $pid ) { # parent # feed LWP results into $child_fh close $child_fh; } else { # child # STDIN is the parent exit; }
Re: Can you get LWP data in a stream?
by derby (Abbot) on Dec 05, 2007 at 17:35 UTC
Re: Can you get LWP data in a stream?
by Anonymous Monk on Dec 06, 2007 at 08:04 UTC
    use :content_file, then give XML parser the filename
      Yeah... thought of that. Annoying but may be the best solution.

                      - Ant
                      - Some of my best work - (1 2 3)