Please forgive my ignorance, but what's wrong with it? $foo ends up as 1 when $bar is true and is undefined when $bar is false. Just as I expect it to be. (Active Perl 5.8.7)
Wrong. This piece of code is one of the weird things in perl, in this case, something that is sometimes used as a dirty trick, to create a static variable.
#!/usr/bin/perl -lw
print $];
for (1 .. 5) {
my $i = 123 if $bar;
print ++$i;
}
Result:
Name "main::bar" used only once: possible typo at test.pl line 4.
5.008003
1
2
3
4
5