in reply to generating hash from array

Is this what you wanted?
Note: this does handle the command->test thing you asked for as well. Will also prevent duplicates.
#!/usr/bin/perl + use strict; use Data::Dumper; my @arr = qw(comp1-cmd1-test1 comp1-cmd1-test2 comp1-cmd2-test1 comp2- +cmd1-test1 comp2-cmd1-test2 comp3-cmd1-test1); my $ret_struct; foreach my $element (@arr) { my ($comp, $cmd, $test) = split(/\-/, $element); push(@{$ret_struct->{$comp}{$cmd}}, $test) unless(grep(/$test/, @{$ret_struct->{$comp}{$cmd}})); push(@{$ret_struct->{$cmd}}, $test) unless(grep(/$test/, @{$ret_struct->{$cmd}})); } print Dumper($ret_struct);

Here is the output

$VAR1 = { 'cmd2' => [ 'test1' ], 'comp2' => { 'cmd1' => [ 'test1', 'test2' ] }, 'comp3' => { 'cmd1' => [ 'test1' ] }, 'cmd1' => [ 'test1', 'test2' ], 'comp1' => { 'cmd2' => [ 'test1' ], 'cmd1' => [ 'test1', 'test2' ] } };

Replies are listed 'Best First'.
Re^2: generating hash from array
by rsennat (Beadle) on Oct 21, 2005 at 16:55 UTC
    Thanks a LOTTTTT, Chester, Davidrw, AMW1.

    That's really a gr8 stuff!!!!!

    Thanks
    Senthil