Hello,
I've made a two dimensional array using references, which I gather is the only way to do it in Perl. I now need to pass each interior array to a subroutine for processing and can't quite work out the syntax. Here's what I have so far. As you can see, my understanding of Perl falls apart when I get to the subroutine. Any help would make my day. Thanks.
[CODE=perl]
my @fruitFiles =("apple.html ", "orange.htm l", "kiwi.html" );
my @vegetableFiles =("pea.html", "carrot.htm l", "limabean.html" );
my @breadFiles =("rye.html", "wheat.html ", "sevenGrain.htm l");
#Make references to arrays.
my $fruitArray = \@fruitFiles;
my $vegArray = \@vegetableFile s;
my $breadArray = \@breadFiles;
# Put references into an array to make a two-dimensional array.
@categoryArrays = ($fruitArray, $vegArray, $breadArray);
#Proof of concept, debug.
for my $i (0..$#categoryA rrays) {
for my $j (0..$#{$categor yArrays[$i]}) {
print "\$i = $i, \$j = $j, $categoryArrays[$i][$j]\n";
}
}
for my $q (0..$#categoryA rrays) {
#pass each array to subroutine.
&buildList ($categoryArray s[$q]);
}
sub buildList($catA rray)
{
@locArray = $catArray;
foreach $element (@locArray)
{
print $element;
print "\n";
# I actually want to open all of the files in the passed array, manipulate and concatenate bits of them into an output file.
# I think I can manage that part if I can just reference them correctly down here.
}
}
[/CODE]
I've made a two dimensional array using references, which I gather is the only way to do it in Perl. I now need to pass each interior array to a subroutine for processing and can't quite work out the syntax. Here's what I have so far. As you can see, my understanding of Perl falls apart when I get to the subroutine. Any help would make my day. Thanks.
[CODE=perl]
my @fruitFiles =("apple.html ", "orange.htm l", "kiwi.html" );
my @vegetableFiles =("pea.html", "carrot.htm l", "limabean.html" );
my @breadFiles =("rye.html", "wheat.html ", "sevenGrain.htm l");
#Make references to arrays.
my $fruitArray = \@fruitFiles;
my $vegArray = \@vegetableFile s;
my $breadArray = \@breadFiles;
# Put references into an array to make a two-dimensional array.
@categoryArrays = ($fruitArray, $vegArray, $breadArray);
#Proof of concept, debug.
for my $i (0..$#categoryA rrays) {
for my $j (0..$#{$categor yArrays[$i]}) {
print "\$i = $i, \$j = $j, $categoryArrays[$i][$j]\n";
}
}
for my $q (0..$#categoryA rrays) {
#pass each array to subroutine.
&buildList ($categoryArray s[$q]);
}
sub buildList($catA rray)
{
@locArray = $catArray;
foreach $element (@locArray)
{
print $element;
print "\n";
# I actually want to open all of the files in the passed array, manipulate and concatenate bits of them into an output file.
# I think I can manage that part if I can just reference them correctly down here.
}
}
[/CODE]
Comment