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. | [reply] [d/l] [select] |
Oh, duh.
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] |