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
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;还是比较。。。

你可能感兴趣的:(TO,while,use,strict,errors,execution,allowed,of,aborted,not,due,compilation,Bareword)