With regard to your first question, you've done it about as easily as it can be done; only other option I see is to change:
@new_hashes = map{ my $x = $_; +{ map { $_=>$x->{$_} } @wanted_keys }
+} @old_hashes;
to
@new_hashes = map { my %x; @x{@wanted_keys}=@$_{@wanted_keys}; \%x } @
+old_hashes; # untested
Update: I see someone else already said that. To provide some new content, here's a different answer to the second question:
@cols = (split(' ', $data, 4),
(map scalar reverse, reverse split(' ', reverse($data), 4))[1
+..3]);
Update: I actually "tested" that, and completely failed to notice that it did nothing like what I wanted. Try this
instead:
@cols = split(' ', $data, 4);
@cols[7,6,5,4,3] = map scalar reverse, split ' ', reverse($cols[3]), 5
+;
or the all in one version:
@cols = ((split(' ', $data, 4))[0..2], reverse map scalar reverse, spl
+it ' ', reverse((split ' ', $data, 4)[-1]), 5);
Side note:
${\(expr)} does the same thing as (expr)[-1], and in fewer characters if you can omit the parentheses.
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.