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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|