LWP::Simple::head($url) -- Return value

LWP::Simple::head($url) -- Return value

am 31.10.2010 12:52:23 von Jatin

Hi All

I had the following code to test what the head() method of the
LWP::Simple module returns.

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

my $url = 'http://oreilly.com/store/complete.html';
#my $url = 'http://www.garimela.com/complete.html';

my $testvar = head($url);
print "head when used in scalar context is: $testvar \n";

print "Success \n" if ($testvar);

my @listvar = head($url);
print "head when used in a list context is: @listvar \n";

OUTPUT:
---------------
head when used in scalar context is: HTTP::Response=HASH(0x861cd00)
Success
Use of uninitialized value $listvar[3] in join or string at catalog.plx
line 15.
head when used in a list context is: text/html; charset=utf-8 462143
1288520055 Apache

My Questions:
-----------------------
1. From the module's documentation i can understand that the return
value of the head() method in a scalar context is TRUE , but what does
the value returned by the server which is HTTP::Response=HASH(0x861cd00)
signify ?
2. Why am i getting a warning message in the line 3 of the output ?

Thanks
Jatin

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: LWP::Simple::head($url) -- Return value

am 31.10.2010 13:53:45 von Shawn H Corey

On 10-10-31 07:52 AM, Jatin wrote:
> 1. From the module's documentation i can understand that the return
> value of the head() method in a scalar context is TRUE , but what does
> the value returned by the server which is HTTP::Response=HASH(0x861cd00)
> signify ?

It is a hash reference. See `perldoc perlref`.

> 2. Why am i getting a warning message in the line 3 of the output ?

Because its value is undef.

To see what's in your variables, `use Data::Dumper`.

use Data::Dumper;

print '$testvar ', Dumper $testvar;

print '@listvar ', Dumper \@listvar;



--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/