无法将散列和字符串传递给函数,在perl中一起!

无法将散列和字符串传递给函数,在perl中一起!,第1张

概述我基本上试图将字符串和哈希传递给perl中的子例程. sub coru_excel { my(%pushed_hash, $filename) = @_; print Dumper(%pushed_hash);} 但似乎数据正在变得混乱.转储的数据还包括$filename.这是输出. ...................$VAR7 = 'Address';$VAR8 = [ 我基本上试图将字符串和哈希传递给perl中的子例程.

sub coru_excel {    my(%pushed_hash,$filename) = @_;    print Dumper(%pushed_hash);}

但似乎数据正在变得混乱.转储的数据还包括$filename.这是输出.

...................$VAR7 = 'Address';$VAR8 = [          '223 VIA DE................        ];$VAR9 = 'data__a.xls'     <----- $filename$VAR10 = undef;$VAR11 = 'DBA';$VAR12 = [           'J & L iNC..................         ];

以下是我调用子程序的方法.

coru_excel(%hash,"data_".$first."_".$last.".xls");
解决方法 参数作为一个无差别列表传递给子例程.

一种解决方案是颠倒参数的顺序,以便标量是第一个.

sub coru_excel {    my($filename,%pushed_hash) = @_;}coru_excel("file_name",%hash);

另一种方法是通过引用传递哈希:

sub coru_excel {    my($pushed_hash_ref,$filename) = @_;}coru_excel(\%hash,"file_name");
总结

以上是内存溢出为你收集整理的无法将散列和字符串传递给函数,在perl中一起!全部内容,希望文章能够帮你解决无法将散列和字符串传递给函数,在perl中一起!所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1268594.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-08
下一篇2022-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存