in reply to A cleaner way of scoping variables
I suppose you could hide $bar in a subroutine:{ my $bar; if ($foo) { $bar = "true"; } print $bar; }
But that's an extreme solution.sub test { my $arg = shift; my $bar; if($arg) { $bar = "true"; } return $bar; } my $foo = 1; print test($foo);
Update:
This approach eliminates the global and the curlies:
:-)use strict; my $foo = 1; if ($foo) { package Strange; our $bar = "true"; } print $Strange::bar || "false";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A cleaner way of scoping variables
by hmerrill (Friar) on Aug 09, 2004 at 13:54 UTC | |
by Arunbear (Prior) on Aug 09, 2004 at 15:21 UTC | |
|
Re: A cleaner way of scoping variables
by bradcathey (Prior) on Aug 09, 2004 at 16:40 UTC |