I have some trouble with showing data in an array. I have 2 arrays and I put one array in another :
my @array1;
my @arraygroup
push (@array1, "a");
push (@array1, "b");
push (@arraygroup, @array1);
This seems to be no problem for perl, when I use the following loop I get " ab " as a result :
foreach my $array (in $arraygroup) {
print $array;
}
I want to address each item in array1 separately though, so I try the following :
foreach my $array (in $arraygroup) {
print $array[0];
}
Which doesn't work since I defined $array instead of @array, so I change this :
foreach my @array (in $arraygroup) {
print $array[0];
}
This won't work either because foreach requires a $variable to be declared and won't take an array instead. How should I get this thing to work ?
Also, are there better alternatives to double arrays in Perl ? I use these often in Java but I haven't found much about them in Perl yet. I'm wondering why they aren't that common.
my @array1;
my @arraygroup
push (@array1, "a");
push (@array1, "b");
push (@arraygroup, @array1);
This seems to be no problem for perl, when I use the following loop I get " ab " as a result :
foreach my $array (in $arraygroup) {
print $array;
}
I want to address each item in array1 separately though, so I try the following :
foreach my $array (in $arraygroup) {
print $array[0];
}
Which doesn't work since I defined $array instead of @array, so I change this :
foreach my @array (in $arraygroup) {
print $array[0];
}
This won't work either because foreach requires a $variable to be declared and won't take an array instead. How should I get this thing to work ?
Also, are there better alternatives to double arrays in Perl ? I use these often in Java but I haven't found much about them in Perl yet. I'm wondering why they aren't that common.