in reply to Re: Re: Re: Reducing LWP Buffering
in thread Reducing LWP Buffering
You can't pass parameters to a callback, so you have to either pass a closure or do some other magic. I haven't tried anything like this recently, and thus I write simply untested code from the top of my head:
use strict; use LWP::UserAgent; my $url = 'http://www.example.com/'; my $filename = 'test.file'; open CONTENT, "<", $filename or die "Couldn't open $filename : $!"; binmode CONTENT; my $callback = sub { my $content; my $size = read( CONTENT, $content, 51200 ); $content = "" unless $size; $content; }; my $ua = LWP::UserAgent->new(); $ua->post($url,$callback);
For anything fancier, I strongly suggest you learn about anonymous code references and closures.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Reducing LWP Buffering
by Anonymous Monk on Dec 05, 2003 at 14:22 UTC |