Hi,
What I intend to do here is to append the corresponding array from all the possible combination of the keys in the given HoA. The number of hash maybe varying from HoA to HoA (>10 hashes/HoA). Size of array is fixed for each HoA.
My question is how can I construct a dynamic way to combine (append) array + combined key of HoA for the new_HoA?
Given the (idiot) working code I have below, here are the desired output answers:
my %set_hoa1_output = ( 't1' => ["A","A","A","A"], 't2' => ["B","B","-","B"], 't3' => ["C","-","-","C"], 't1t2' => ["AB","AB","A-","AB"], 't1t3' => ["AC","A-","A-","AC"], 't2t3' => ["BC","B-","--","BC"], 't1t2t3'=> ["ABC","AB-","A--","ABC"] );
my %set_hoa2_output = ( 'k1' => ["A","A","-"], 'k2' => ["D","-","-"], 'k1k2' => ["AD","A-","--"], );
__BEGIN__ #!/usr/bin/perl -w use strict; use Data::Dumper;
#These two hashes are *not related* they serve only as example my %set_hoa1 = ( 't1'=> ["A","A","A","A"], 't2'=> ["B","B","-","B"], 't3'=> ["C","-","-","C"], );
my %set_hoa2 = ( 'k1'=> ["A","A","-"], 'k2'=> ["D","-","-"], );
my %output_hash = get_item_set(%set_hoa1); print Dumper \%output_hash;
sub get_item_set { my %hoa = @_; my %new_hoa;
#First, assigning hash with single key for my $key (keys %hoa ) { $new_hoa{$key} = $hoa{$key}; }
# This is an idiot way (manual) to do it and it's not dynamic # i.e. only satisfy for %set_hoa1 # How can I construct automatically so that it may apply to varying # number of hashes in HoA (%set_hoa2 .. etc) ?
my @tmp = map{ $hoa{"t1"}[$_] . $hoa{"t2"}[$_]} (0 .. $#{$hoa{"t1"}});
$new_hoa{"t1"."t2"} = [EMAIL PROTECTED];
my @tmp2 = map{ $hoa{"t2"}[$_] . $hoa{"t3"}[$_]} (0 .. $#{$hoa{"t1"}});
$new_hoa{"t2"."t3"} = [EMAIL PROTECTED];
my @tmp3 = map{ $hoa{"t1"}[$_] . $hoa{"t3"}[$_]} (0 .. $#{$hoa{"t1"}});
$new_hoa{"t1"."t3"} = [EMAIL PROTECTED];
my @tmp4 = map{ $hoa{"t1"}[$_] . $hoa{"t2"}[$_] . $hoa{"t3"}[$_] } (0 .. $#{$hoa{"t1"}});
$new_hoa{"t1"."t2"."t3"} = [EMAIL PROTECTED];
return %new_hoa; }
__END__
Thanks so much for your time.
-- Regards, Edward WIJAYA SINGAPORE
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>