File :: Find and $ _ in nested routines

When you run the following code, the file names of all the files below C: \ Test are printed. Why doesn't it print only Hello(n times, depending on how many files are processed)?

Does this mean that I cannot rely on shiftto securely appoint $_? Imagine that an employee implements a function wtfand does not know what he called from a fake File::Find. I am running this code with Strawberry Perl 5.12

Edit: this code also doesn't work like this:

use strict;
use warnings;

wanted();

sub wanted{
    wtf("Hello");
}

sub wtf {
    shift;
    print; #expecting Hello 
}

So, I think I'm completely off the highway here .. This obviously has nothing to do with File :: Find, now I'm looking for a new name for this question. Here is my original code:

use strict;
use warnings;

use File::Find;

find(\&wanted, "C:\\test");

sub wanted{
    wtf("Hello");
}

sub wtf {
    shift;
    print; #expecting Hello 
}
+3
3

print $_, shift @_. , , @_, $_. shift , - :

sub wtf {
    my $_ = shift;
    print;
}

, $_ ​​ , @_ ​​ . CPAN File::Find .

+4
+2

, File:: Find CPAN - (: File:: Find:: Rules File:: Find:: Object). :: Find - , , .

0

Source: https://habr.com/ru/post/1748119/


All Articles