tags:

views:

74

answers:

1

I have created HTTP::Request which looks like this:

 #!/usr/bin/perl
require HTTP::Request;
require LWP::UserAgent;
require HTTP::Cookies;

$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$cookie_jar = HTTP::Cookies->new();
$ua->cookie_jar($cookie_jar);
$cookie_jar->set_cookie(0,'testCookie','cookieValue','/','http://www.google.com/',80,0,0,86400,0);

$response = $ua->request($request);
if($response->is_success){
print "sucess\n";
print $response->code;
print "\n";
}
else {
print "fail\n";
die $response->code;
print "\n";
}

now, When i send Request: i want to log the http response codes in the file

please help thank you

+1  A: 

If you want to print to a file, then print to a file:

 open my($log), '>', $log_file or die "Could not open $log_file: $!";

 ....

 if($response->is_success){
     print $log "success:", $response->code, "\n";
 }
 else {
     print $log "fail: ", $response->code, "\n";
 }

The general way to solve these sorts of issues is figure out what you want to do then find out how to do that by looking in the docs or a Perl tutorial. Most of the things you will ever want to do will be just combining the basics you'll find in Learning Perl.

brian d foy
when i used above code gave me following message :Could Not open $log file do i need to create the file somewhere can you please elaborate more
dexter
As I said in the last sentence, you probably want to go through _Learning Perl_.
brian d foy