in reply to Populating Arrays of Arrays
use strict; use warnings; # a plethora of my's ...strict baffles me # ** deleted ** Wait until you need them to declare them #two arrays of arrays to populate # ** Starting out as arrays of strings my @aoa=qw/header font content/ ; my @aoac=qw/headerc fontc contentc/; # array of array values my @contents=( ["html","head","body",], ["font","face","size","color"], ["h1","p","code"] ); #scalar ref to array for later population my $scalarclose=\@aoac; #** Now @$scalarclose is the same as @aoac #** and $scalarclose->[1] is the same as $aoac[1], etc. #populate the aoa # ** you're just copying. Same as @aoa = @contents; #** Declare this outside the loop, so it doesn't get reset every itera +tion my $i; #use contents of populated aoa foreach my $val (@aoa) { # an incrementer hacked to use for populating # an aoa with modified values ++$i; my $count=$i-1; #get values from original aoa and modifiy, #begin population of new aoa our $length=scalar @$val; my @ctags; for (0...$length-1) { my $ctag="<\\$val->[$_]>"; push @ctags, $ctag ; } my $newlength=$length+1; #** You never do anything with this, but... my @ctagarray=splice @ctags, 0, $newlength; #this line is problematic #** What do you want to do with scalarclose? It is a scalar (array + ref) $scalarclose->[$count]=[map {$_} @ctagarray]; #** or @$scalarclose = map {$_} @ctagarray; #** of course, your map is just identity, so that's @$scalarclose = @ctagarray; } #scalar refs to aoa #** values are being copied from @aoac, which was never an AoA. my $headc=$aoac[0]; my $fontc=$aoac[1] ; my $contentc=$aoac[2]; #** So let's copy from @aoa, which is an AoA ($headc, $fontc, $contentc) = @aoa; #print to see the populus >>broken<< #** Since we copied references into them, you can now dereference them print " $headc->[1]\n"; print " $fontc->[1]\n"; print " $contentc->[1]\n";
|
|---|