I don't believe the OP's issue came from reading chained operations, but more from the switch between left-chaining and right-chaining in the revised code.

His one-liner:

%h = ( map { $_, $h{$_} } sort { $a<=>$b } keys %h)[0,1];

was structured like:

 %h = ( op3 op2 op1 %h) op4;

where %h was acted upon by four operators in turn (keys, sort, map, and an array slice). But the order of operation was not linear. It flowed to the left, then sharply cut back to the right. In pseudo-scheme, that would have been:

(set! 'h (hash-new (array-slice (1 2) (flatten-map (lambda (x) (list x (hash-get h x))) (sort stringcomp (hash-keys h))))))
and the dataflow would have been clear. A while ago on the Perl 6 language lists there was discussion of 'gozinta' operators which would have allowed you to adjust the order of things. I don't remember the exact syntax right now (and it may have been squashed, I forget), but his code could have been done something like so:
%h ==> keys ==> sort { $a<==>$b } ==> map { $_, %h{$_} } ==> [0,1] ==> + %h;
or...
%h <== [0,1] <== map { $_, %h{$_} } <== sort { $a<==>$b } <== keys <== + %h;
Either way would have worked, and the dataflow is obvious without having to switch left/right more often.

In reply to Re^2: small steps toward Perl literacy, temp vars and parentheses by BlaisePascal
in thread small steps toward Perl literacy, temp vars and parentheses by rir

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.