in reply to conditional definition of variables
"my" declares a variable. A variable should not be declared more than once in a block. Simply leave out the (second) "my":
$var = "zzz\n" unless defined $var;
However, if you want to print the variable, you should make sure that $var is defined (otherwise you get a warning with "use warnings;"):
$var = defined($var) ? "zzz\n" : "";
By the way, including another script with "do" isn't good practice. Consider making it a module (perlmod).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: conditional definition of variables
by stephanm (Sexton) on Aug 23, 2008 at 14:12 UTC | |
by JavaFan (Canon) on Aug 23, 2008 at 14:38 UTC |