Okay, now I'm nervous ;-) My reason for asking is purely academic--I'm trying to REALLY learn Perl (yes I have read the Llama book and am plowing through the Camel tome). However, instead of starting with what I don't understand, let me start with what I do (I do understand your first reply to this post and even much of the Linux article referenced).
It appears that in the first line:
my %hash = map { my $item = pop @$_; map { $_, $item } @$_ }
you are mapping a key and value to %hash from an array. Next, it looks like a string of "HELP" redirects flow to a sub (as does the last line "QUIT"...).
Now, what I don't understand, specifically, how are the keys and values being mapped into the hash (where are they coming from)? What does
pop @$_ do (couldn't find
@$_ explained anywhere)? How does the last bit on that first line work?
map { $_, $item } @$_
Lastly, why are there square brackets bookending lines 2 and 3?
I may not be ready for this heady stuff, but I'm willing to try. Thanks
merlyn.
Update:Thanks to
runrig and his
reply. I get it in theory, but not in practice. Though it has encouraged a more thorough understanding of
map. I'll look at this in a couple of months and probably get it fine. Thanks.
—Brad
"A little yeast leavens the whole dough."
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.