Two examples that eliminate the need for $bar entirely.
my $foo = 1; print +($foo)? "True" : "";
Or, if it's more involved than that...
my $foo = 1; print do{ if( $foo ) { "True" } }
In your last example, you asserted that it would be nice if $bar were accessible outside of the if(){} block. But you previously stated that you didn't want to use a global variable (in this case what you really meant was a lexical scoped to package level). The problem is that if $bar is accessible outside of the if(){} block, it's no different from a package-scoped lexical. You don't want your lexicals leaking outside of the block they're defined in; that defeats the purpose of a lexical variable.
Dave
In reply to Re: A cleaner way of scoping variables
by davido
in thread A cleaner way of scoping variables
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |