[PLUG] Perl 3D array - printing all values

Paul Heinlein heinlein at madboa.com
Wed Oct 22 14:16:02 UTC 2003


On Wed, 22 Oct 2003, Matt Alexander wrote:

> >> foreach my $x ( @myarray ) {
> >>   foreach my $y ( @{$x} ) {
> >>     foreach my $z ( @{$y} ) {
> >>       print $myarray[$x][$y][$z], "\n";
> >>     }
> >>   }
> >> }
>
> Even more interesting is that I ran a test with 3 elements and it
> brought my computer to a screaching halt with the following message:
>
> Use of reference "ARRAY(0x804c970)" as array index at testing.pl
> line 10.

Well, it was off the cuff. :-) How about this?

foreach my $x ( @myarray ) {
  foreach my $y ( @{$myarray[$x]} ) {
    foreach my $z ( @{$myarrray[$x][$y]} ) {
      print $myarray[$x][$y][$z], "\n";
    }
  }
}

--Paul Heinlein <heinlein at madboa.com>




More information about the PLUG mailing list