[PLUG] Perl 3D array - printing all values
Colin Kuskie
ckuskie at dalsemi.com
Wed Oct 22 14:08:02 UTC 2003
On Wed, Oct 22, 2003 at 01:47:22PM -0700, Colin Kuskie wrote:
> On Wed, Oct 22, 2003 at 01:12:16PM -0700, Matt Alexander wrote:
> > This should be an easy one for you Perl gurus... ;-)
> >
> > I have a 3 dimensional array in Perl...
> >
> > $myarray[$val1][$val2][$val3]
> >
> > I would like to print every value in the array.
>
> Cheap, but works depending on the end product.
>
> use Data::Dumper;
>
> print Dumper(\@myarray);
And this will print the data without the Perl syntax:
foreach my $x ( @myarray ) {
foreach my $y ( @{$x} ) {
print join(" " @{$y}), "\n";
}
}
which is just a sloppy way of doing what Paul did:
foreach my $x ( @myarray ) {
foreach my $y ( @{$x} ) {
foreach my $z ( @{$y} ) {
print "$z\n";
}
}
}
Colin
More information about the PLUG
mailing list