5.10 throws a warning for that type of construct
No it doesn't. I seem to recall that blead did, at some point, but it appears to no longer do so.
It has changed the behaviour, now the assignment just becomes undefined, but the previous value is not recovered from the pad.
#! /usr/local/bin/perl5.9.5 use strict; use warnings; a(10); a(0); a(20); sub a { my $num = shift; my $x = $num * 100 if $num; print $x, $/; } # produces # 1000 # Use of uninitialized value $x in print at ./myif line 13. # 2000
Real state variables are now available with the state declarator:
sub c { state $count = 10; return $count++; } print c(), $/; # 10 print c(), $/; # 11 print c(), $/; # 12
• another intruder with the mooring in the heart of the Perl
In reply to Re^2: Curious result of using "my ... if ..."
by grinder
in thread Curious result of using "my ... if ..."
by jrw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |