in reply to declaring same variable
"my @x if condition" is quite dangerous, because it creates a kind of global variable with restricted scope! If this is in a subroutine, the second time you call the sub, you get exactly the same array, not a new one.
But anyway.. this switch-like initiation is very common, and I like to write it like this:
my @xxx = $op eq 'numbers' ? (one, two, three)
: $op eq 'alpha' ? (four, five)
: $op eq 'alp' ? (six, ten)
: die; # or ()
Just one of many ways to express the same.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: declaring same variable
by davido (Cardinal) on Jan 21, 2004 at 09:44 UTC |