Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Generating Hash-of-List using map?

by LanX (Chancellor)
on Sep 24, 2013 at 10:19 UTC ( #1055464=note: print w/replies, xml ) Need Help??


in reply to Re^3: Generating Hash-of-List using map?
in thread Generating Hash-of-List using map?

> So there is really no way around first declaring the hash and then filling it. What a pity!

O come on! Just "cheat"! ;-)

DB<113> @CELLS = ("A-1", "B-2", "C-3", "A-4", "B-5", "C-6", "A-7", " +B-8", "C-9") => ("A-1", "B-2", "C-3", "A-4", "B-5", "C-6", "A-7", "B-8", "C-9") DB<114> %hash = map { /^([^-]*)-(.*)$/; if( $1 eq ($a//'-') ) { push + @$b, $2; () } else { ( $a = $1 => $b = [ $2 ] ) } } sort @CELLS; => ("A", [1, 4, 7], "B", [2, 5, 8], "C", [3, 6, 9])

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055464]
help
Chatterbox?
[james28909]: ok, i think im going to dive on into OO. i need to keep track of users in a program i have and the easiest way seems to be OO. does anyone have a good site that they knowof for someone wanting to start in O programming?

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-05-25 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?