in reply to Array is empty when using if else condition
To expand on what flexvault said: you're using @SPECores as both a lexical and a global variable. The lexical declaration (my @SPECores) in your if() { ... } block shadows the global variable, so you're writing to the lexical variable, but when it goes out of scope at the end of the block, the global variable becomes visible again, and that's what you print.
use strict; might've given you a clue here, BTW:
Global symbol "@SPECores" requires explicit package name at 1098850.pl + line 17. Execution of 1098850.pl aborted due to compilation errors.
Always use strict. It's your friend, and will catch many mistakes and potential sources of headaches for you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array is empty when using if else condition
by jellisii2 (Hermit) on Aug 28, 2014 at 20:28 UTC | |
|
Re^2: Array is empty when using if else condition
by kaka_2 (Sexton) on Aug 28, 2014 at 14:25 UTC |