sub foo{
my $x if 0;
print "FOO: ", $x++, "\n";
}
sub bar{
my $x if 0;
print "BAR: ", $x--, "\n";
}
foo, bar for (1..10);
with
sub foo{
print "FOO: ", $x++, "\n";
}
sub bar{
print "BAR: ", $x--, "\n";
}
foo, bar for (1..10);
I reckon the real reason is the explanation given by Abigail.
Now I don't think I would ever write my $x if 0 unless I wanted to get the sack for writing obscure code, but how about:
sub STATIC_VARIABLE{ 0 }
sub foo{
STATIC_VARIABLE && my $x;
print "FOO: ", $x++, "\n";
}
would that be difficult to understand? Would it carry on working in the future?
--
iakobski |