#4 – The Strict Pragma July 24, 2006
Posted by takeuaway in Basic Perl, chapter 1.trackback
A pragma is a special perl module that hints the compiler the way a block of statements should be compiled. If the program disobeys the restrictions placed on it, it won’t compile. Here is an example:
———————————————
#!C:/Perl/Bin/Perl
use strict “subs”;
$name = Ellie;
print “Hi $name”;
———————————————-
The 2nd line tells the compiler to use the module – strict, with subs as the argument. If this line is not available, the compiler will compile smoothly and print the following result:
Hi Ellie
However, the existence of this 2nd line will give the following outcome:
Bareword “Ellie” not allowed while “strict subs” in use at try_pragma.pl line 3.
Execution of try_pragma.pl aborted due to compilation errors.
The use function call allows users to use modules located in the standard Perl library, which is located at C:\Perl\lib in windows.
When the strict pragma takes “subs” as an argument, it will capture any bare words, or unquoted strings, when the script is being compiled. The program will abort with an error message.
Comments»
No comments yet — be the first.