[root@localhost ~]# less test
#!/usr/bin/env perl
use strict;
use warnings;
my $name = Fred;
print "hello\n" if $name =~ /red/;
[root@localhost ~]# ./test
Bareword "Fred" not allowed while "strict subs" in use at ./test line 4.
Execution of ./test aborted due to compilation errors.
[root@localhost ~]#
当注释了use strict的时候就正常了
[root@localhost ~]# less test
#!/usr/bin/env perl
#use strict;
use warnings;
my $name = Fred;
print "hello\n" if $name =~ /red/;
[root@localhost ~]# ./test
hello
[root@localhost ~]#
因为变量赋值没有加引号,看来加了use strict;还是比较。。。
转载于:https://blog.51cto.com/myunix/1212405
本文介绍了一个简单的Perl脚本示例,展示了如何使用strict模块来帮助发现脚本中的常见错误,并解释了为什么在使用strict时某些代码会引发错误。

1万+

被折叠的 条评论
为什么被折叠?



