rsennat has asked for the wisdom of the Perl Monks concerning the following question:
I would like to convert this to a hash like this,comp1-cmd1-test1 comp1-cmd1-test2 comp1-cmd2-test1 comp2-cmd1-test1 comp2-cmd1-test2 comp3-cmd1-test1
Can anyone of you please help me to get thru this. I found some perl modules in CPAN which is not elaborate to be used.%hoh = ( "comp1" => { "cmd1" => [ "test1", "test2" ], "cmd2" => [ "test1" ] }, "comp2" => { "cmd1" => [ "test1", "test2" ] }, "comp3" => { "cmd1" => [ "test1" ] }, );<br>
But this is not sufficient to get it the way I need.%hoh = (); foreach my $temp (sort @{$arr1} ) { my ($comp, $cmd, $test) = split(/\-/, $temp); $hoh{$temp} = { comp => $comp, cmd => $cmd, test => $test, }; }
20051021 Janitored by Corion: Added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: generating hash from array
by chester (Hermit) on Oct 21, 2005 at 15:27 UTC | |
|
Re: generating hash from array
by davidrw (Prior) on Oct 21, 2005 at 15:31 UTC | |
|
Re: generating hash from array
by amw1 (Friar) on Oct 21, 2005 at 15:37 UTC | |
by rsennat (Beadle) on Oct 21, 2005 at 16:55 UTC | |
|
Re: generating hash from array
by pg (Canon) on Oct 21, 2005 at 17:20 UTC | |
|
Re: generating hash from array
by rsennat (Beadle) on Oct 21, 2005 at 17:48 UTC |