I getuse strict; my @myarr; my $lpn; my $ppn; my $i; for ($i=0;$i<15;$i++) { ($lpn, $ppn) = get_ns($i); push @{ $myarr[$lpn] }, $ppn; } for my $index (0..$#myarr) { next unless defined $myarr[$index]; my @tmp; for my $subindex (0..scalar(@{$myarr[$index]})-1) { my $date; for ($date=0;$date<10;$date++) { $tmp[$date] = get_date($index, $subindex); } push @{$myarr[$index][$subindex]}, [ @tmp ]; } } sub get_ns { return (int(rand(100)), int(rand(100))); } sub get_date { return get_ns; }
when I try to run it, and my lineCan't use string ("23") as an ARRAY ref while "strict refs" in use at +./eg.pl line 24.
push @{$myarr[$index][$subindex]}, [ @tmp ];
seems to be the problem - I've tried all the variations on syntax I can remember trying to hit on the correct one and searched perlmonks for similar questions but I can't find examples with 3 levels of array and moving from 2 to 3 seems to be my problem. However perhaps I am not seeing that somewhere I am making a mistake higher up and that I am indeed referencing it right but not stuffing the right values and hence causing the error, I am not sure.
If anyone can point out my error it would be hugely appreciated.
Pete
In reply to Adding cols to 3d arrays - syntax by peterrowse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |