Hello keepers of knowledge,
I have humble request, to shed some light and guide fellow monk apprentice.
I stumble across some piece of Perl code, which I cannot really wrap my head around.
It suppose to create an intersection of two arrays (with lower casing all characters).
my @intersection =
grep { defined }
@{ { map { lc ,=> $_ } @a } }
{ map { lc } @b };
I've run it through deparse to see what's not seen by naked eye.
$ perl -MO=Deparse -e 'my @intersection =
grep { defined }
@{ { map { lc ,=> $_ } @a } }
{ map { lc } @b };
'
my(@intersection) = grep({defined $_;} @{+{map({lc $_, $_;} @a)};}{map
+ {lc $_;} @b});
-e syntax OK
So this explained me that ',=> $_' is actually just ', $_' but is there a reason for using a fat comma, or is it "Winking fat comma" (still dunno why it's used)?
Why 1st map is enclosed by @{} is it dereferencing output of map?
Probably it's something easy. I just want to understand the mechanics and maybe learn something new.
thanks
m.
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.