![]() |
|
Think about Loose Coupling | |
PerlMonks |
Re^2: small steps toward Perl literacy, temp vars and parenthesesby BlaisePascal (Monk) |
on Jun 16, 2004 at 21:54 UTC ( #367449=note: print w/replies, xml ) | Need Help?? |
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: 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: or... Either way would have worked, and the dataflow is obvious without having to switch left/right more often.
In Section
Meditations
|
|