Do you know where your variables are? | |
PerlMonks |
Re: Where to declare?by blackmateria (Chaplain) |
on Oct 24, 2001 at 22:02 UTC ( [id://121216]=note: print w/replies, xml ) | Need Help?? |
Move the declaration of @dirlist after the nested sub (getAns), then pass it in as a hard reference:
For more information on hard references, take a look at perlref. Just a stylistic note, you don't need to put the & on getAns to call if if you're already using () (the original has a line which read my @dirs = &getAns()). As a matter of fact, you should stay away from using & to call subroutines unless you understand how it's different from calling them with (). Calling with & makes @_ in the called subroutine an alias for @_ in the caller; () makes a copy instead. So changing the parameters in the subroutine could affect the variables used in the main program. This is probably not what you expect! Be careful. If I were you, I'd change the places in your code that call &getAns to getAns(). Anyway, hope this helps.
In Section
Seekers of Perl Wisdom
|
|