Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

%_ is a hash. You can have a hash named _ because _ is a valid name for a variable. (I'm sure you are familiar with $_ and @_.)

No Perl builtin currently sets it or reads it implicitly, but punctuation variables are reserved. "Perl variable names may also be a sequence of digits or a single punctuation or control character (with the literal control character form deprecated). These names are all reserved for special uses by Perl"

Punctuation variables can't be declared as lexical variables, which is why my %_; is failing. As with other punctuation variables, the best you can do is local %_;. Keep in mind that use strict; won't help remind you of the need to do this, so it's more error prone than using a non-punctuation variable.

Punctuation variables are also special in that they are "super globals". This means that unqualified reference %_ refers to %_ in the root package, not %_ in the current package.

$ perl -E' %::x = ( "%::x" => 1 ); %::_ = ( "%::_" => 1 ); %Foo::x = ( "%Foo::x" => 1 ); %Foo::_ = ( "%Foo::_" => 1 ); package Foo; say "%x = ", keys(%x); say "%_ = ", keys(%_); say "%::x = ", keys(%::x); say "%::_ = ", keys(%::_); say "%Foo::x = ", keys(%Foo::x); say "%Foo::_ = ", keys(%Foo::_); ' %x = %Foo::x %_ = %::_ <-- surprise! %::x = %::x %::_ = %::_ %Foo::x = %Foo::x %Foo::_ = %Foo::_

This means that forgetting to use local %_ can have very far-reaching effects.


In reply to Re: What is %_ by ikegami
in thread What is %_ by Russ

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-19 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found