in reply to Making a variable in a sub retain its value between calls

Note: this relies on undocumented behavior. The behavior it depends on may be changed without warning.
sub foo { my $x if 0; print "X is ", $x++, $/; } foo() for 3 .. 5; ---- X is 0 X is 1 X is 2

Replies are listed 'Best First'.
Re^2: Making a variable in a sub retain its value between calls
by ikegami (Patriarch) on Apr 19, 2005 at 04:52 UTC
    It is documented. It is documented as being undefined behaviour, which is even less reliable than undocumented.