in reply to Re: HTTP response buffer
in thread HTTP response buffer

That sorta works. The file is a wav audio file, and when I print out the $data from the callback to a new file, it isn't opening. Do you think I need to convert the $data into a different format?
$browser = LWP::UserAgent->new(); my $resp = $browser->get($url,':content_cb' => sub { my($data, $resp) = @_; open FILE, ">>1.wav" or die $!; print FILE $data; close FILE; return; },':read_size_hint' => 1024);

Replies are listed 'Best First'.
Re^3: HTTP response buffer
by Corion (Patriarch) on Feb 23, 2009 at 21:15 UTC

    You should binmode the file after opening it. I wouldn't reopen the file on every run through:

    open my $fh, '>', $filename or die "Couldn't create '$filename': $!"; binmode $fh; $browser = LWP::UserAgent->new(); my $resp = $browser->get($url,':content_cb' => sub { my($data, $resp) = @_; print $fh $data; return; },':read_size_hint' => 1024); close $fh;
      I love you?