develooper Front page | perl.perl5.porters | Postings from February 2015

Re: [perl #123910] `undef $0;` does not work

Thread Previous | Thread Next
From:
Lukas Mai
Date:
February 23, 2015 21:46
Subject:
Re: [perl #123910] `undef $0;` does not work
Message ID:
54EB9FBB.1020400@gmail.com
Am 23.02.2015 um 22:18 schrieb (via RT):
> # New Ticket Created by
> # Please include the string:  [perl #123910]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=123910 >
>
>
>
> This is a bug report for perl from porton@narod.ru,
> generated with the help of perlbug 1.40 running under perl 5.20.1.
>
>
> -----------------------------------------------------------------
> [Please describe your issue here]
>
> "Use of uninitialized value $0 in undef operator" is wrong.
>
> $ cat z.pl
> print "$0\n";
> undef $0;
> $ perl -Mstrict -Mwarnings z.pl
> z.pl
> Use of uninitialized value $0 in undef operator at z.pl line 2.

Well, the warning message could be better. '$0 = undef' and '$| = undef' 
have similarly misleading diagnostics ("Use of uninitialized value $| in 
scalar assignment at -e line 1.").

$ perl -we '$0 = my $x'
Use of uninitialized value $0 in scalar assignment at -e line 1.

This one is flat out wrong: The uninitialized value is $x, not $0.

The issue is that $0 and $| are special: $0 is not a real scalar but a 
string internally (an interface to argv[0]) whereas $| is a bit flag. So 
any assignment to $0 will stringify the value in question, which for 
undef triggers a warning.

So "Use of uninitialized value $0 in scalar assignment" should really be 
"Use of uninitialized value in scalar assignment to $0", and "Use of 
uninitialized value $0 in undef operator" should be "Use of 
uninitialized value undef in $0" or something.

-- 
Lukas Mai <plokinom@gmail.com>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About