http://qs1969.pair.com?node_id=1214403


in reply to What is the purpose of local *_ = \my $a in File::Find?

local $_ could be used to localize $_, but that doesn't remove any magic associated with it on some versions of Perl.

$ perl -wE'for ($|) { local $_; $_ = "abc"; say; }' Argument "abc" isn't numeric in scalar assignment at -e line 1. 0

local *_ would do the trick by forcing an entirely new $_ to be created, but that also gets rid of @_, %_, etc.

$ perl -E'$_="x"; @_=(4,5); say $_,@_; local *_; say $_,@_;' x45

Assigning to a glob is weird, though. It only assigns to the relevant slot. So that means assigning a reference to a scalar to *_ only replaces $_

$ perl -E'$_="x"; @_=(4,5); say $_,@_; local *_ = \my $a; say $_,@_;' x45 45

Any fresh scalar would have worked.

Note that this aliases $_ to the scalar, but File::Find does not take advantage of that feature.