Perl   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了perl – 任何人都可以向我解释这个只读的例外情况吗?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
下面是我的代码(不要担心模块顶部有USUW)

我正在测试数组引用是否是只读的,如果是这种情况,那么我将它复制到另一个数组引用.测试显示该数组不是只读的,但是当它运行时,它会因该错误而失败. (对于那些不熟悉我或Smart::Comments的人 – 那些###是Smart::Comments.)

### readonly( $arg_ref ) : readonly( $arg_ref )
### readonly( @$arg_ref ) : readonly( @$arg_ref )
my @ro = map { readonly( $_ ) } @$arg_ref;
### @ro
if ( readonly $arg_ref ) {
    $arg_ref = [ @$arg_ref ];
}
return map { my $val = shift @$arg_ref;
             $_ => $val 
            } @_ 
            ;

这是我得到的输出:

### readonly( $arg_ref ) : 0
### readonly( @$arg_ref ) : 0

### @ro: [
###        0,###        0,###        0
###      ]

但这是错误:

Modification of a read-only value attempted at ....pm line 247.

(247是:

return map { my $val = shift @$arg_ref;

)

有没有人对这个问题有所了解?我们正在运行Perl 5.8.7.有关如何解决它的任何想法?

解决方法

它看起来不像 Scalar::Util::readonly的结果可以信任使用你想如何使用它.见证人:
perl -MScalar::Util=readonly -MReadonly -wle'
    Readonly my $arg_ref => [ qw(a b c)];
    print readonly $arg_ref;
    $arg_ref = 1;'

打印:

0
 Modification of a read-only value attempted at -e line 1.

(使用Readonly 1.03,Scalar :: Util 1.23在perl5.8.8下测试)

大佬总结

以上是大佬教程为你收集整理的perl – 任何人都可以向我解释这个只读的例外情况吗?全部内容,希望文章能够帮你解决perl – 任何人都可以向我解释这个只读的例外情况吗?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: