in reply to small steps toward Perl literacy, temp vars and parentheses

I offer another right-to-leftification of your example:
%h = map { $_->[0], $h{$_->[0]} } [ sort { $a<=>$b } keys %h ];
Do you find it more readable? Personally, I found the line breaks and indentation that other posters provided was more helpful in adding readability than making the direction consistent. But if you're going to do it on one line, it is helpful to have things go one direction.

Update: is this better or worse?

%h = map { $_, $h{$_} } map { $_->[0] } [ sort { $a<=>$b } keys %h ];
Take the keys, sort them, take the first one, and make the hash from the hash entry.

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: small steps toward Perl literacy, temp vars and parentheses
by rir (Vicar) on Jun 17, 2004 at 20:51 UTC
    I find your version about the same. BlaisePascal's snippet and yours move me more toward:
    %h = map { $_, $h{$_} } ( sort { $a <=> $b } keys %h )[0];
    But I don't see this as that important. My post was not about re-writing a bit of code so I could find it an easier read. My post was about improving code reading skills so all code is easier to read.

    How much complexity one can absorb on one line seems to me to be a good thing to increase. Contrarily, perhaps I should try to derive more info from the indentation of code.

    Be well.