Very nice! Let's make it work on a hash reference:
$h_ref = { map lc, %$h_ref };
For those of you who don't quite follow, here are the rules:
- In list context, a hash returns a list of key => value pairs. This is the same thing you use when you *create* a hash. There's no guaranteed order, though, which is rather the point.
- map iterates over the elements of a list, applies some transformation to each, and produces an equally-sized list of the results.
- map lc, %list iterates over the keys and values of the hash (by design, a value follows its key) and lowercases each.
- The right side of the expression is evaluated first, so the same variable can be used on both sides.
- Wrapping the map statement in curly braces turns the resulting list into an anonymous hash.</li.
- Assigning that to the original hash reference makes sure the old, potentially upper-cased keys and values are no longer there.
You can get by without the anonymous hash construction, but I thought it was more clear. map is nice.
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.