in reply to Why $FIle::Find::prune = 1 returns used only once error

There is always no warnings 'once';. My personal preference is to use this locally to the error, so that you cam still detect inadvertent cases of this elsewhere in your code.

sub wanted { if ($File::Find::name =~ m%^/path/detection%){ no warnings 'once'; $File::Find::prune = 1; return; } }

Don't worry about adding execution time to your subroutine; this pragma is applied at compile time.

Replies are listed 'Best First'.
Re^2: Why $FIle::Find::prune = 1 returns used only once error
by ikegami (Patriarch) on Apr 19, 2021 at 21:08 UTC

    Or mention it twice.

    sub wanted { if ($File::Find::name =~ m%^/path/detection%){ $File::Find::prune = 1; return; } } require File::Find; $File::Find::name if 0; $File::Find::prune if 0;

    Seeking work! You can reach me at ikegami@adaelis.com

Re^2: Why $FIle::Find::prune = 1 returns used only once error
by h2 (Beadle) on Apr 18, 2021 at 19:43 UTC

    This was a nice one too, I didn't know about the no warnings 'once' to get rid of such warnings on start, that could be in general useful. However, I just realized, after reviewing this thread, that in the end, I used prune = 1 twice once I got the first one debugged, in two blocks, and that made the Perl warning go away of course, since it was used 2 times, but I will note the no warnings 'once' for future reference.