assign_name();print_name();sub assign_name { $name = "alice";}sub print_name { print $name;}
但是当我使用严格;然后我知道我必须在使用之前声明变量.我读到某个地方我应该使用我们而不是我来声明一个全局变量.所以我有以下几点:
use strict;use warnings;assign_name();print_name();sub assign_name { our $name = "alice";}sub print_name { print $name; # This is line 12.}
然后我收到以下错误:
Variable "$name" is not imported at test.pl line 12.Global symbol "$name" requires explicit package name at test.pl line 12.Execution of test.pl aborted due to compilation errors.
请帮忙.
解决方法 只需声明变量,两个潜艇都可以看到它.use strict;use warnings;my $name;assign_name();print_name();sub assign_name { $name = "alice";}sub print_name { print $name;}
(我没有理由在这里使用!)
总结以上是内存溢出为你收集整理的在Perl中,如何在子例程之间共享变量,使用严格?全部内容,希望文章能够帮你解决在Perl中,如何在子例程之间共享变量,使用严格?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)