BTW, the static trick only works with if 0; and for ();
Not so. Observe:
#!/usr/local/bin/perl -l sub horror { my $foo if "reset" eq shift; print ++$foo; } horror($_) for qw(foo bar baz reset bing bang boom); __END__ 1 2 3 4 1 2 3
(Not that the sub name is intended as an editorial comment, or anything... <grin>)
The nasty part is just that the cleanup (resetting $foo to undef) takes place at the end of the iteration in which my $foo is actually executed (which isn't exactly what you'd expect from a "reset" argument, but that's what you get with silly example code).
In reply to Static variables (oh, the horror())
by ChemBoy
in thread Never lock $0 inside of a BEGIN block
by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |