in reply to declaring same variable
Just declare the variable first (my @xxx;) and then set it in a separate statement (just the way you have it is fine, once the my's are removed and a my @xxx; added at the top).
The warning you got should alert you that each time you say my @xxx, you are creating a new variable named @xxx and hiding the old one: almost certainly not what you want.
Others have warned you of the evils of my whatever if condition; perldoc perlsyn says:
NOTE: The behaviour of a my statement modified with a statement modifier conditional or loop construct (e.g. my $x if ...) is undefined. The value of the my variable may be undef, any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: declaring same variable
by Anonymous Monk on Jan 20, 2004 at 18:53 UTC |