On 11-05-07 11:47 AM, eventual wrote:
Hi,
Looking at the script below, how do I pass 2 arrays from the main script into
the subroutine? Thanks
#### script ######
#!/usr/bin/perl
use strict;
my @whatever = qw(a b c d e);
my @test = qw(1 2 3 4 5 6 7);
{
sub testing {
my (@data1 , @data2) = @_;
print "\@data1 = @data1\n";
print "\@data2 = @data2\n";
}
}
&testing (@whatever ,@test);
You have to use references to the arrays:
#!/usr/bin/env perl
use strict;
use warnings;
my @whatever = qw(a b c d e);
my @test = qw(1 2 3 4 5 6 7);
sub testing {
my @data1 = @{ $_[0] };
my @data2 = @{ $_[1] };
print "\@data1 = @data1\n";
print "\@data2 = @data2\n";
}
testing( \@whatever, \@test );
__END__
Also, don't call a sub with the &. Does can do unexpected things.
See:
perldoc perlreftut
perldoc perlref
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/