[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;还是比较。。。
本文转自 freeterman 51CTO博客,原文链接:http://blog.51cto.com/myunix/1212405,如需转载请自行联系原作者