|
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
|