|< 1 2 >| | 17 Einträge, 2 Seiten |
QuoteIf you want to pass more than one array or hash into a function--or return them from it--and have them maintain their integrity, then you're going to have to use an explicit pass-by-reference.
$x=subroutine($var_a,\@list_a,$var_b,\@list_b)
sub subroutine($\@$\@) { ... }
$x = subroutine($var_a, @list_a, $var_b, @list_b)
1
2
3
4
5
6
7
8
sub subroutine {
my $var_a = shift;
my *arr_a = shift;
my $var_b = shift;
my *arr_b = shift;
#...
}
1
2
syntax error at -e line 4, near "my *arr_a"
syntax error at -e line 6, near "my *arr_b"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
#
my $a = "abc";
my $b = "123";
my @a = qw(a b c);
my @b = qw(1 2 3);
subroutine($a,\@a,$b,\@b);
sub subroutine {
local ($sa,*aa,$sb,*ab) = (@_);
print "$sa\n$sb\n";
print "@aa\n@ab\n";
}
|< 1 2 >| | 17 Einträge, 2 Seiten |