Click here to get back home

empty variables - getting rid of "uninitialized value" warnings?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
empty variables - getting rid of "uninitialized value" warnings? Tomasz Chmielewski 03-28-2008
Posted by szr on March 31, 2008, 7:24 pm
Please log in for more thread options
Frank Seitz wrote:
> szr wrote:
>> Gunnar Hjalmarsson wrote:
>>>
>>> use warnings;
>>> @execargs = undef;
>
> Better:
> @execargs = (undef);

Yes. The effect is the same, but this makes it clearer. Why someone
would do this in practice is another question entirely, though.

>>> if (exists $execargs[0] && $execargs[0] ne '') {
>>> # ...
>>> }
>>>
>>> C:\home>perl test.pl
>>> Use of uninitialized value $execargs[0] in string ne at test.pl line
>>> 3.
>>
>> I ran the same test and got the same result.
>>
>> Removing the " && $execargs[0] ne '' " portion prevented the error.
>
> Yes, because this test produces the warning.

Yes I now understand why it was coming out that way, thanks.

>> This works too:
>>
>> if (exists $execargs[0] && !!$execargs[0]) {
>>
>> (Tested in 5.10.0, 5.8.8, and 5.6.1)
>>
>> So I wonder, since " exists $execargs[0] " fails,
>
> No, "exists $execargs[0]" succeeds, because there is an element 0.

Oh, yeah, because of the assingment of C<undef> to the array. My brain,
the same.

Thanks.

--
szr



Similar ThreadsPosted
portable no warnings "uninitialized" January 10, 2005, 8:26 am
catching "Use of uninitialized value" warnings September 29, 2006, 7:38 pm
uninitialized value warnings and run time January 4, 2007, 2:45 pm
Creating empty variables for input data March 26, 2007, 4:49 pm
use warnings; and use Warnings; give different results August 30, 2004, 2:09 pm
How to construct new variables in a script from other variables and strings. May 12, 2006, 4:51 am
local variables and global variables June 27, 2006, 8:31 am
warnings or -w ? November 5, 2006, 7:24 am
uninitialized? July 6, 2004, 10:56 pm
@_ uninitialized value March 2, 2005, 10:38 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap