What is %_ for?

Since it's not documented in perlvar, I don't think it's for particular use. I think that FunkyMonk's reply is making sense. I also got the same impression upon reading about symbol table in perlmod and perlref.

If there is no current use, would anyone care to suggest what %_ might be used for?

Well, you can use it as you will normally use hash. Initialize it, assign elements to it, get a value from a key. Since it's sort, it's also perfect for golf. And it can also be confusing so one may use it in obfucasted code. You can use it to alias a hash variable with some lengthy you'd be tried to type it over and over.

my %hash_variable_with_not_actually_that_long_name = (one => 1); print $hash_variable_with_not_actually_that_long_name{one}, "\n"; *_ = \%hash_variable_with_not_actually_that_long_name; print $_{one}, "\n"; # output 1 1
Additionally, with the aliasing, you can alias other sigils at once. But, by using _ you're likely to get into problem.
$_ = 2; print $_, "\n"; *_ = *hash_variable_with_no_actually_that_long_name; print $_{one}, "\n"; print $_, "\n"; # output 2 1 (empty, with 'uninit' warnings under -w)

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: Does %_ have a function or is it just for fun? by naikonta
in thread Does %_ have a function or is it just for fun? by larard

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.