in reply to Re: Curious result of using "my ... if ..."
in thread Curious result of using "my ... if ..."
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Curious result of using "my ... if ..."
by blazar (Canon) on May 16, 2007 at 14:30 UTC | |
by jdporter (Paladin) on May 16, 2007 at 14:35 UTC | |
by blazar (Canon) on May 16, 2007 at 15:02 UTC | |
by jdporter (Paladin) on May 16, 2007 at 16:06 UTC | |
by blazar (Canon) on May 16, 2007 at 19:06 UTC |