#!/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 overhead
for my $ref (@Mdevices) {
print join(' - ', @{$ref}),"\n";
}
####
$VAR1 = [
[
'UnitID',
'fileno'
]
];
UnitID - fileno
####
my (@Cdevices,@Mdevices);
push (@Cdevices, 'UnitID1', 'fileno1');
push (@Cdevices, 'UnitID2', 'fileno2'); # <- @Cdevices is now qw(UnitID1 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";
}