Rich36 has asked for the wisdom of the Perl Monks concerning the following question:
Variable "@dirlist" will not stay shared at test.pl line 17. Variable "@dirlist" will not stay shared at test.pl line 24.
Where/how do I declare that variable to avoid that warning? If I place the "my @dirlist" within the "getAns()" sub, it redeclares the variable and erases any information that was added. If I leave it out of that sub, I get that warning.
#!/usr/bin/perl -w use strict; my @dirs = &getDirs(); sub getDirs() { my @dirlist; # PROBLEM!!! sub getAns() { print qq(Enter a valid directory: ); chomp(my $ans = <STDIN>); if ($ans ne "") { if ($ans =~ m/foo/g) { push(@dirlist, $ans); &getAns; } else { print qq(That is not a valid directory!\n); &getAns; } } else { return @dirlist; } } } my @dirs = &getAns(); if (@dirs) { return @dirs; } else { die qq(No directories have been entered!\n); } }
Thanks in advance for the help,
Rich36
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where to declare?
by Masem (Monsignor) on Oct 24, 2001 at 21:58 UTC | |
by traveler (Parson) on Oct 24, 2001 at 23:11 UTC | |
|
Re: Where to declare?
by blackmateria (Chaplain) on Oct 24, 2001 at 22:02 UTC | |
|
Re: Where to declare?
by Rich36 (Chaplain) on Oct 24, 2001 at 22:25 UTC | |
by tye (Sage) on Oct 24, 2001 at 23:36 UTC |