Having dinked around with the example for a bit, I think that the chief reason it is awkward to read is that it's kludgy. You're getting the minimum key value by sorting and indexing, instead of by using a min function.
use List::Util;
my $min_key = min(keys %h);
%h = ($min_key, $h{$min_key});
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):
%h = map { $_, $h{$_} } min(keys %h);
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.
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.
We're not really tightening our belts, it just feels that way because we're getting fatter.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.