prints#!/usr/bin/perl use strict; use warnings; my (@Cdevices,@Mdevices); push (@Cdevices, 'UnitID', 'fileno'); push (@Mdevices, \@Cdevices); # this will show us the actual layout of the array use Data::Dumper; print Dumper(\@Mdevices); # $k=0; $k<=$#Mdevices; $k++ is C-style. Possible, but unnecessary ove +rhead for my $ref (@Mdevices) { print join(' - ', @{$ref}),"\n"; }
update: after reading the OP again, it now becomes a bit more clear to me what he actually wants to do and I also found out what the problem is. Look at the following code:$VAR1 = [ [ 'UnitID', 'fileno' ] ]; UnitID - fileno
You want the first element of each sub-array, but there is only one sub-array!!! you would need something like this: push (@Cdevices, ['UnitID3', 'fileno3']); # that will store a reference to an anonymous arraymy (@Cdevices,@Mdevices); push (@Cdevices, 'UnitID1', 'fileno1'); push (@Cdevices, 'UnitID2', 'fileno2'); # <- @Cdevices is now qw(UnitI +D1 fileno1 UnitID2 fileno2) push (@Cdevices, 'UnitID3', 'fileno3'); # <- and so on push (@Mdevices, \@Cdevices); # this makes it clear: use Data::Dumper; print Dumper(\@Cdevices); print Dumper(\@Mdevices); for my $ref (@Mdevices) { print $ref->[0],"\n"; }
In reply to Re: Multidimensional array
by svenXY
in thread Multidimensional array
by igor1212
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |