in reply to multidimensional arrays
You should be able to build the array to as many dimensions as you want using recursion. I don't quite understand what you're doing (its also late and my brain is rebelling), but here is some incomplete code to give you the general idea.
my $ranges = [ { I => "2", }, { I => "3", J => "2", }, { I => "4", J => "3", K => "2", } ]; foreach my $rvarHASH ( @{ $ranges } ) { my @rvarLIST = sort keys %$rvarHASH; my $depth = scalar @rvarList; my $array = BuildArray(\@rvarLIST, $depth); # do whatever with $array ... } sub BuildArray{ my ($rvarLISTref, $depth) = @_; my $arrayref; $depth--; if ($depth > 0){ # last dimension not reached, so do another recursion my $rtn = BuildArray($rvarLISTref, $depth); # get index, set ref to next dimension in array $ii = ... $arrayref->[$ii] = \$rtn; }else{ # arrived at last dimension, # get index, set value into array $ii = ... $arrayref->[$ii] = $netlist; } return $arrayref; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: multidimensional arrays
by Anonymous Monk on Jun 10, 2007 at 10:07 UTC |