If we wanted a statement that could be read from right to left completely we could use
"Take the keys of %h, sort them numericaly, take the first one and set the %h hash to the key and its value."%h = ( $_, $h{$_}) for ($_) = sort {$a <=> $b} keys %h;
But I think this one is even more confusing. Maybe this
would be better, the comma giving a hint that we do expect the sort to return several values, but we use just the first one.%h = ( $_, $h{$_}) for ($_,) = sort {$a <=> $b} keys %h;
Anyway in this case I would use some temp variable. Even though I did work with some functional languages and liked it :-)
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
In reply to Re^3: small steps toward Perl literacy, temp vars and parentheses
by Jenda
in thread small steps toward Perl literacy, temp vars and parentheses
by rir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |