Maybe offtopic but keep in mind that when passing more than one parameter the parameter list will be flattened. You do need references in that case to distinguish between the items in your parameter list!
The following code doesn't consider the two different arrays, it only sees one long parameter list.
#! /usr/bin/perl
use strict;
use warnings;
my @array1 = ( 1, 2, 3, 4, 5);
my @array2 = ( 1, 2, 3, 4, 5);
list(@array1,@array2);
sub list {
foreach my $c (@_) {
print $c . " ";
}
}
The following code only expects references and will treat each reference as an array reference.
#! /usr/bin/perl
use strict;
use warnings;
my @array1 = ( 1, 2, 3, 4, 5);
my @array2 = ( 1, 2, 3, 4, 5);
list(\@array1,\@array2);
sub list {
foreach my $r (@_) {
foreach my $c (@$r) {
print $c . " ";
}
print "\n";
}
}
--
if ( 1 ) { $postman->ring() for (1..2); }
|