Tom Christiansen wrote:
> 
> >The warning for the use of an unassigned variable should be "use of
> >uninitialized variable C<$x>".
> 
> The problem with that idea, now as before, is that this check happens
> where Perl is looking at a value, not a variable.  Even were it possible
> to arduously modify Perl to handle explicitly named simple variables,
> there's much more to consider.
> 
>     if ( fx() == fy() ) { }
> 
> For one.
> 
> --tom

Yes, we've been through this before. :-) And now, as before, that's not
what the RFC is saying. Your fx() example would produce the warning "use
of undefined value". No variable name. Same for the code C<my @x =
(1,2,3); print $x[32]>. I am not changing the existing warning at all,
just rewording it from "uninitialized" to "undefined", because that's
what it is. 'Initialized' means you've assigned something to it at least
once; undefined means defined() returns false.

I am merely suggesting that the compiler detect, when it can, that
you're trying to use the value of a variable without ever having
assigned a value to that variable. And in THAT message, you had better
know the name of the variable, since it's the basis of the analysis. And
yes, it only handles simple named variables.

Example:

1 my ($x, $y, $z);
2 $z = 1;
3 my $logfile = "/tmp/log";
4 $x = 1 if cond();
5 print $x+$y;
6 undef $z;
7 print $z;

--> use of uninitialized variable $y in line 5 (compile time)
--> possible use of uninitialized variable $x in line 5 (compile time)
--> variable $logfile defined in line 3 but never used (compile time)
--> use of undefined value in line 7 (run time)

I'll add this example to the RFC.

Reply via email to