vagabonding electron has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
this is most certainly a misunderstanding of a scope issue but I cannot solve this puzzle myself.
The following code works:
#!/perl use strict; use warnings; use File::Find; my $dir = qw(N:/TMP); find( \&wanted, $dir ); sub wanted { print "[$dir] $File::Find::dir $File::Find::name\n"; }
However if I try to call the same in the loop:
my @dir = ( qw( N:/TMP N:/TMP_2 )); for my $dir ( @dir) { find( \&wanted, $dir ); }
it dies with the message:
Global symbol "$dir" requires explicit package name at ...
If I call the same as an anonyme subroutine, it works:
for my $dir ( @dir) { find( sub {print "[$dir] $File::Find::dir $File::Find::name\n";}, $dir ); }
Could you please explain this behavior?
Thanks in advance.
VE
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File::Find in a loop
by fishmonger (Chaplain) on Apr 28, 2013 at 16:35 UTC | |
by vagabonding electron (Curate) on Apr 28, 2013 at 17:29 UTC | |
Re: File::Find in a loop
by NetWallah (Canon) on Apr 28, 2013 at 16:07 UTC | |
by Anonymous Monk on Apr 29, 2013 at 09:05 UTC | |
by NetWallah (Canon) on Apr 29, 2013 at 15:19 UTC | |
by Anonymous Monk on May 01, 2013 at 08:42 UTC | |
Re: File::Find in a loop
by RichardK (Parson) on Apr 28, 2013 at 16:08 UTC | |
Re: File::Find in a loop
by vagabonding electron (Curate) on Apr 28, 2013 at 16:59 UTC | |
Re: File::Find in a loop
by tobyink (Canon) on Apr 29, 2013 at 00:40 UTC | |
Re: File::Find in a loop
by Laurent_R (Canon) on Apr 28, 2013 at 21:05 UTC | |
by 2teez (Vicar) on Apr 28, 2013 at 21:45 UTC | |
by Laurent_R (Canon) on Apr 28, 2013 at 22:27 UTC | |
by Anonymous Monk on Apr 28, 2013 at 22:55 UTC |
Back to
Seekers of Perl Wisdom