Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: from array to hash with grep

by bart (Canon)
on Jun 15, 2006 at 08:27 UTC ( [id://555449]=note: print w/replies, xml ) Need Help??


in reply to Re^2: from array to hash with grep
in thread from array to hash with grep

It's still possible but you'll have to use something closer to what sonofason wrote. For each match, you need to create a ($key, $value) pair so the list constructed by map is more like ($key1, $value1, $key2, $value2, $key2, $value3) for the three values. That way, assigning to the hash will insert them as you want.

Now the code you can use to do that, can read for example:

@flat = map { /\w{3}_(\w)/ ? ($1, $_) : () } @inp;
It'll create a pair like ("A", "abc_A_bla") for a match, and an empty list for no match.

Assign to the hash, and you get:

%inp = map { /\w{3}_(\w)/ ? ($1, $_) : () } @inp;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://555449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found