in reply to Re: small steps toward Perl literacy, temp vars and parentheses
in thread small steps toward Perl literacy, temp vars and parentheses
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:(set! 'h (hash-new (array-slice (1 2) (flatten-map (lambda (x) (list x (hash-get h x))) (sort stringcomp (hash-keys h))))))
or...%h ==> keys ==> sort { $a<==>$b } ==> map { $_, %h{$_} } ==> [0,1] ==> + %h;
Either way would have worked, and the dataflow is obvious without having to switch left/right more often.%h <== [0,1] <== map { $_, %h{$_} } <== sort { $a<==>$b } <== keys <== + %h;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: small steps toward Perl literacy, temp vars and parentheses
by Jenda (Abbot) on Jun 16, 2004 at 22:18 UTC | |
by ysth (Canon) on Jun 23, 2004 at 08:14 UTC | |
Re^3: small steps toward Perl literacy, temp vars and parentheses
by dragonchild (Archbishop) on Jun 17, 2004 at 03:07 UTC |
In Section
Meditations