Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A very handy skill in learning Perl is gaining familiarity with documentation. I personally use the Perl documentation hosted on http://perl.org with associated hook-up to my browser search box to keep it immediately on hand. There's also the perldoc command-line utility, ActiveState bundles html-ified docs with its version, and I'm sure a plethora of other options.

For operators, there's perlop. Within that document, the => operator is documented under Comma Operator. It is identical to a comma, except to transforms a bareword left-hand argument to a string. Specifically,

The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores.
Thus it allows:

my %passwords = ("Matt" , "s1k1d52", "scuzzy" , "2ab928", "Marky" , "s8291s", "Jeb" , "jeb23", );

to be written as

my %passwords = (Matt => "s1k1d52", scuzzy => "2ab928", Marky => "s8291s", Jeb => "jeb23", );

which I find to be more intuitive.

The each function has a bit of magic in it. When called with a hash, it will set an iterator in the hash and returns a key, value pair. Each subsequent call (assuming you don't use another function that sets an iterator) returns another key/value pair until they are exhausted, at which time it will return and empty list or undef depending on context. Thus, a while(each) will systematically traverse a hash. On each iteration, I use list assignment to store the key/value pair and then output them in an interpolated string. The examples in each are likely more clear than any explanation I can give.


In reply to Re^3: hash problems by kennethk
in thread hash problems by weglarz

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 having an uproarious good time at the Monastery: (6)
As of 2024-03-29 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found