http://www.perlmonks.org?node_id=928063


in reply to Re^2: Simulating --keep-session-cookies wget option with LWP ?
in thread Simulating --keep-session-cookies wget option with LWP ?

Your code works for me, once I fix it to actually become a program:

use strict; use HTTP::Cookies; use LWP::UserAgent; # try to simulate wget: my $cookie_jar = HTTP::Cookies->new( file => "mycookie.cookie", autosave => 1, ); my $ua = LWP::UserAgent->new; $ua->timeout(2); $ua->cookie_jar($cookie_jar); $ua->env_proxy; if( !@ARGV) { warn "Requesting page"; my $request= HTTP::Request->new (GET=> "http://www.google.com/webhp?hl +=en"); my $status=$ua->request ($request); if ($status->is_success) { print $status->decoded_content(); } else { print STDERR $status->status_line, "\n"; return 1; } }; use Data::Dumper; warn "Cookies in jar:"; $cookie_jar->scan(sub { warn Dumper \@_ });

It (re)generates the cookie file if run without any command line argument, and if run with a command line argument, it just dumps the cookies from the file.

Whatever your problem seems to be, I would suspect that it lies elsewhere.