use strict; #### (SOME_ERROR_TEXT) at (FILE) line (LINE). Execution of (FILE) aborted due to compilation errors. #### # Code: $x = 5; # no strict 'vars' print "$x\n"; # Output: Global symbol "$x" requires explicit package name at strict-demo.pl line 10. Global symbol "$x" requires explicit package name at strict-demo.pl line 11. Execution of strict-demo.pl aborted due to compilation errors. #### my $x; # declare first $x = 5; # strict okay print "$x\n"; #### $newPig = 'Keisha'; # much, much later... print $Newpig; # prints nothing; why? #### # Code: my $subroutine = factorial; # no strict 'subs' print $subroutine->(7), "\n"; # Output: Bareword "factorial" not allowed while "strict subs" in use at strict-demo.pl line 13. Execution of strict-demo.pl aborted due to compilation errors. #### my $subroutine = \&factorial; # strict okay print $subroutine->(7), "\n"; #### # Code: our $dog; my $pet = 'dog'; ${ $pet } = 'Rover'; # no strict 'refs' print "$dog\n"; # Output: Can't use string ("dog") as a SCALAR ref while "strict refs" in use at strict-demo.pl line 18. #### our $dog; my $pet = \$dog; # hard reference ${ $pet } = 'Rover'; # strict okay print "$dog\n"; #### no strict 'vars'; no strict 'subs'; no strict 'refs'; #### # strict-demo.pl # = Copyright 2011 Xiong Changnian = # = Free Software = Artistic License 2.0 = NO WARRANTY = use strict; # comment out to avoid errors #----------------------------------------------------------------------------# # Uncomment lines to force strict errors... # $x = 5; # no strict 'vars' # print "$x\n"; # my $subroutine = factorial; # no strict 'subs' # print $subroutine->(7), "\n"; # our $dog; # my $pet = 'dog'; # ${ $pet } = 'Rover'; # no strict 'refs' # print "$dog\n"; #----------------------------------------------------------------------------# # Uncomment this whole section for a successful run... # my $x; # declare first # $x = 5; # strict okay # print "$x\n"; # my $subroutine = \&factorial; # strict okay # print $subroutine->(7), "\n"; # our $dog; # my $pet = \$dog; # hard reference # ${ $pet } = 'Rover'; # strict okay # print "$dog\n"; #----------------------------------------------------------------------------# print "Done.\n"; sub factorial { my $in = shift; my $out = 1; for my $factor (2..$in) { $out *= $factor; }; return $out; }; __END__