"uninitialized value in join or string"

L

laurent

Hi there,


I picked up this script below in the newsgroup, and i noticed that
it works but also generate an warning, -or a complaining message ;
How could it be improved ? by my self i added line 3, but without
success :

The script is here (it returns headers of an http server)

[laurent@joanna_2 laurent]$ cat !*
cat w_perl.pl
#!/usr/local/bin/perl -w

use LWP::Simple;
my @response = (); <---added line

# Send a head request and populate the array
@response = head("http://www.lemonde.fr/");

print "@response\n";



Thx,

laurent
 
P

Purl Gurl

laurent wrote:

(snipped)
it works but also generate an warning, -or a complaining message ;
How could it be improved ?

Turn off warnings.

There is no need for usage of warnings nor strict
with a simple three to five line script.

Purl Gurl
 
J

Jeff Schwab

Purl said:
laurent wrote:

(snipped)




Turn off warnings.

There is no need for usage of warnings nor strict
with a simple three to five line script.

Patient: Doc, I took my pulse, and it's way to high.
I'm scared. What should I do?

Doctor: Don't take your pulse.
 
L

laurent herve

Joe said:
That should be
print @response if @response;


i did it :

print "@response\n" if "@response";

and i get the message twice, so i guess that this
array --- > @response , is seing as not initialized,
but therefore i tried to initialize it in line 3 !

Each time i will use/access to @response, i will
get this "unitialized valu in join or string"

Now, i add at the end

@response = ();

Then i didn't get the message once more, so it means
that it is a matter of the content of the array ?

laurent
 
J

Joe Smith

laurent said:
Joe Smith wrote:





i did it :

print "@response\n" if "@response";

No, no, no. That should be
print @response,"\n" if @response;
or
print "Start---\n",@response,"End-----\n" if @response.

You must not use double quotes when testing to see if the @response
array is populated.
-Joe
 
L

laurent herve

Joe Smith wrote:

No, no, no. That should be
print @response,"\n" if @response;
or
print "Start---\n",@response,"End-----\n" if @response.

You must not use double quotes when testing to see if the @response
array is populated.
-Joe

With or without the double quotes, i get an output, and foremost,
the same output. I said that the warning message depends of the
content of the array, because if i empty the array i get one
message less....
i RTFM .-

laurent
 
J

Joe Smith

laurent said:
With or without the double quotes, i get an output, and foremost,
the same output. I said that the warning message depends of the
content of the array, because if i empty the array i get one
message less....
i RTFM .-

In that case, you need to find out which elements of the array are undef.

@response = head("http://www.lemonde.fr/");
die "Nothing was returned" unless @response;
for (0 .. $#response) {
print "$_: ", (defined $response[$_] ? $_ : '--undef--'), "\n";
}

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top