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.


In reply to Re: What is the purpose of local *_ = \my $a in File::Find? by ikegami
in thread What is the purpose of local *_ = \my $a in File::Find? by YenForYang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.