Hi,
Say I have a hash like this:
my %hash = ("NETWORK1" => "A", "NETWORK2" => "B", "TYPE1" => "C", "TYP
+E2" => "D");
Now I want to create a new hash with only those keys/values where the key =~ m/^NETWORK/
So keys matching /^NETWORK/:
my %hashslice1 = ("NETWORK1" => "A", "NETWORK2" => "B");
And keys matching /^TYPE/:
my %hashslice2 = ("TYPE1" => "C", "TYPE2" => "D");
The problem is... how?
Two functions come to mind: grep and map, but I am not sure how to use those to get to hash slices above.
TIA!
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.