Printing elements of "hash of hash of array" in perl -
i need print elements of following "hash of hash of array"(%partitions). nothing getting printed. also, no error encountered. please help
our %partitions; sub partition{ %set; @array; for(my $i=0;$i<$pop_size;$i++) { for(my $j=0;$j<$min_pr;$j++) { @array=(); for(my $k=0;$k<$tot_nodes;$k++) { if($population[$i]{$k} eq $j) { push @array, $k; } } $set{$j} = [@array]; } $partitions{$i} = [%set]; } foreach $p (sort keys %partitions) { print "$p {\n"; while (my ($r, $s) = %{$partitions->{$p}}) # error in line { # not entering loop print "$r {\n"; print "value: @$s \n"; print "}\n"; } } } partition;
it looks benefit perlreftut, because there several oddities in code use fixing.
$partitions{$i} = [%set];
this creates array reference containing flattened version of hash %set
, isn't intend. think may have meant this:
$partitions{$i} = { %set };
but think maybe %set
should declared inside outer loop.
(on further reading, maybe did mean flatten it.)
this line:
while (my ($r, $s) = %{$partitions->{$p}}) # error in line
should be:
while (my ($r, $s) = each %{$partitions{$p}})
Comments
Post a Comment