Using the strict Pragma : strict « Language Basics « Perl






Using the strict Pragma

   

#A pragma is a module that triggers a compiler to behave in a certain way. 
#The strict pragma can be used to prevent the use of global variables in a program. 
#The 'our' built-in is used when you need a global variable but still want to use the strict pragma


use strict "vars";
my $name = "Tom";               # my (lexical) variables are okay
@friends = qw(Tom A B C);       # global variables not allowed
local $newspaper = "The Globe"; # local variables are not allowed
print "My name is $name and our friends are @friends.\n";

   
    
    
  








Related examples in the same category

1.use strict 'refs';
2.use strict 'subs';
3.use strict 'vars';
4.use strict Pragma
5.use strict;
6.'use strict' and subroutine
7.'use strict' with package
8.no strict 'refs';
9.The strict Pragma