如何將兩個數組和一個字符串傳遞給子?如何將兩個數組和一個字符串傳遞給Perl子例程?
這裏就是我想要做的事:
use strict;
use warnings;
my @x = qw(AAAA BBBB CCCC DDDD EEEE);
my @y = qw(1111 2222 3333 4444 5555);
my $z = "hello";
Hello(@x,@y,$z);
exit(0);
sub Hello {
my (@x,@y,$z) = @_;
print "$_\n" for @x;
print "$_\n";
print "$_\n" for @y;
print "$_\n";
print "$z\n";
}
輸出:
AAA
BBBB
CCCC
DDDD
EEEE
1111
2222
3333
4444
5555
hello
Use of uninitialized value $_ in concatenation (.) or string at test.pl line 19.
Use of uninitialized value $_ in concatenation (.) or string at test.pl line 21.
Use of uninitialized value $z in concatenation (.) or string at test.pl line 22.
,使用子原型(如果它正是如此澄清我贊成票您的答案)Perl的最佳實踐的書不鼓勵 - http://stackoverflow.com/questions/3991474/ IS-使用的原型到申報陣列組基準上下文上子程序-ARGS-A-好/ 3991558#3991558 – DVK 2010-10-21 20:27:55