我想将以下变量传递给子程序mySubroutine,$name,$age,然后是这个多维数组:
$name = "jennifer"; $age = 100; $list[0][0] = "TEST NAME 2"; $list[0][1] = "TEST GROUP 2"; $[0][2] = 10; $[1][0] = "TEST NAME 2"; $[1][1] = "TEST GROUP 2"; $[1][2] = 2;
子程序:
sub mySubroutine { }
我已经尝试了$_ [0]和@_,但我似乎没有得到正确传递给子例程的变量.
解决方法
有几种方法可以实现(像Perl中的大多数事情).我个人这样做:
sub mySubroutine { # Get passed arguments my ($name,$refList) = @_; # Get the array from the reference my @list = @{$refList}; # Good to go } # You need to pass @list as reference,so you # put \@list,which is the reference to the array mySubroutine($name,\@list);