in reply to small steps toward Perl literacy, temp vars and parentheses
That's perfectly clear, efficient, and doesn't involve a lot of slinging data around. If you particularly hate the temp variable, you could obviate it with map (although I find that rather dogmatic):use List::Util; my $min_key = min(keys %h); %h = ($min_key, $h{$min_key});
In the same way that variables should have purposeful names, chunks of code should look like what you're trying to accomplish. If there were no min() function already written, you could (and should) easily write your own, rather than inlining everything.%h = map { $_, $h{$_} } min(keys %h);
Update: if the issue is improving your ability to read code, well, bad code is always going to be hard to read. You could certainly practice at the Perl Golf site. I think that recognizing why good code is good and why bad code is bad is helpful to your literacy.
|
|---|