in reply to static variable hack

I guess I'm missing the mystery. You have my $static and it's undef. It's not going to default to 42 because it's not 0. Once you use the unary op ++, it'll cast undef to a number (in this case 0) and then increment it. Maybe I'm missing something here, and if I am, my apologies. --
I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.

Replies are listed 'Best First'.
Re^2: static variable hack
by ikegami (Patriarch) on Oct 29, 2007 at 20:09 UTC

    Compare

    sub foo { my $var if 0; $var++; print "var is now $var\n"; }

    and

    sub foo { my $var ; $var++; print "var is now $var\n"; }