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

Good day Monks. I am trying to write a script that will use WWW::Mechanize or one of its parent classes to fetch a binary file and write it directly to disk on a windoze system. I can write the file in question (an .exe) as follows:
$response = mech->get($url); open(OUT,">$filename"); binmode $filename; print OUT $response->content; close OUT;
But for large files this takes a lot of memory, so I'd like to dump the file straight to disk.

LWP::UserAgent, which is inherited by Mech, has a method called mirror, that is used thus

$mech->mirror($url,$filename);
It seems from the docs like this should do the trick but when I try it with the same $url and $filename as in the above working example, nothing happens. Will this method not work for binary files on windoze? Is there some other approach I should use?

TIA...

Steve

Replies are listed 'Best First'.
Re: WWW::Mechanize write directly to file?
by grep (Monsignor) on Nov 26, 2006 at 16:39 UTC
    From the POD of WWW::Mechanize:
    get() is a well-behaved overloaded version of the method in LWP::UserA +gent. This lets you do things like $mech->get( $url, ":content_file"=>$tempfile );

    The reference to LWP::UserAgent:

    $ua->get( $url , $field_name => $value, ... ) <snip> If a $filename is provided with the :content_file option, then the + response content will be saved here instead of in the response objec +t.

    grep
    XP matters not. Look at me. Judge me by my XP, do you?