簡體   English   中英

如何將哈希和數組的引用傳遞給子例程

[英]How to pass a reference of a hash and array to subroutine

我正在嘗試將散列引用和數組引用傳遞給子例程,但遇到諸如無效類字符串之類的錯誤:

sub test{
           if($chk == 2)
             {
                return(\%hash,\@array);
              } 
        }


my ($has, $arr)= test();

現在我再次不得不"$has, $arr"的引用傳遞給另一個子例程。

這個怎么做? 我像\\%$has, \\@$arr一樣傳遞它們\\%$has, \\@$arr但這似乎不是傳遞給子例程的正確方法。

做就是了:

anotherSub($has, $arr);

$has$arr已經是引用。

我的%Hash =('1'=>'one');

我的@Arr =('1','2');

&fun(\\%Hash,\\ @ Arr);

sub fun(){

my $Hash_Ref=shift;

my $Arr_Ref=shift;
enter code here
&Fun2($Hash_Ref,$Arr_Ref);

} sub fun2(){

my $Hash_Ref=shift;

my $Arr_Ref=shift; 

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM