File::Find and $_ in nested subroutines.
Posted
by zedoo
on Stack Overflow
See other posts from Stack Overflow
or by zedoo
Published on 2010-06-02T09:19:13Z
Indexed on
2010/06/02
9:24 UTC
Read the original article
Hit count: 201
perl
When running the following code, the filenames of all files below C:\Test are printed. Why doesn't it print just Hello
(n times, depending on how many files are processed)?
Does this imply that I cannot rely on shift
to reliably assign to $_
? Imagine a coworker implements the wtf
function and doesn't know that it's called from a File::Find
wanted sub.
I run this code with Strawberry Perl 5.12
use strict;
use warnings;
use File::Find;
find(\&wanted, "C:\\test");
sub wanted{
wtf("Hello");
}
sub wtf {
shift;
print; #expecting Hello
}
© Stack Overflow or respective owner