Nov 23, 2006

Basic #4, the strict pragma

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”;
———————————————-

2nd Line
The 2nd line tells the compiler to use the module - strict, with subs as the argument.
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.

No comments: