in reply to loading a file from a URL with as little overhead as possible
Thanks shotgunefx and tachyon, see below the result of using LWP::UserAgent. It's much cleaner. And it works under Windows too!
Anything else I could do to improve it?
#!/bin/perl -w use strict; my $BUFSIZE= 32678; # default buffer size for XML::Parser::Expat foreach( @ARGV) { parseurl( $_); } sub parseurl { my( $url)= @_; pipe( README, WRITEME) or die "cannot create connected pipes: $!" +; if( my $pid= fork) { # parent code: parse the incoming file close WRITEME; # no need to write while( <README>) { print ; } close README; } else { # child close README; require LWP; $|=1; my $agent = LWP::UserAgent->new; my $request = HTTP::Request->new( GET => $url); my $response = $agent->request( $request, sub { pass_url_content( \*WRITEME, @_); }, $BUFSI +ZE); $response->is_success or die "$url ", $response->message, "\n" +; close WRITEME; } } sub pass_url_content { my( $fh, $data, $response, $protocol)= @_; print $fh $data; }
|
|---|