我有这个代码有效
@H_301_2@my @new = keys %h1;
my @old = keys %h2;
function(\@new,\@old);
但是可以在不必先声明变量的情况下完成吗?
function必须将其参数作为引用.
解决方法
@H_301_2@use strict;
use Data::Dumper;
my %test = (key1 => "value",key2 => "value2");
my %test2 = (key3 => "value3",key4 => "value4");
test_sub([keys %test],[keys %test2]);
sub test_sub{
my $ref_arr = shift;
my $ref_arr2 = shift;
print Dumper($ref_arr);
print Dumper($ref_arr2);
}
输出:
@H_301_2@$VAR1 = [ 'key2','key1' ]; $VAR1 = [ 'key4','key3' ];