#4 – The Strict Pragma July 24, 2006
Posted by takeuaway in Basic Perl, chapter 1.add a comment
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.
#3 – Literals July 24, 2006
Posted by takeuaway in Basic Perl, chapter 1.add a comment
Numeric Literals
| 12345 | Integer |
| 0×456ff | Hexadecimal |
| 0777 | Octal Numbers |
| 23.45 | Float |
| .234E-2 | Scientific Notation |
String Literals
| Escape Sequence | Description |
| \t | Tab |
| \n | New Line |
| \r | Carriage Return |
| \f | Form Feed |
| \b | Backspace |
| \a | Alarm/Bell |
| \e | escape |
| 33 | Octal Character |
| \xff | Hexadecimal Character |
| \c[ | Control Character |
| \l | Next character is converted to lower case |
| \u | Next character is converted to upper case |
| \L | Next characters are converted to lower case until a \E is found |
| \U | Next characters are converted to upper case until a \E is found |
| \Q | Backslash all following non-alphanumeric characters until a \E is found |
| \E | Ends upper or lower case conversion started with \L or \U |
| \\ | Backslash |
Special Literals
| _LINE_ | Represents the current line number |
| _FILE_ | Represents the current filename |
| _END_ | Represents the logical end of script; trailing garbage is ignored |
#2 – Switches July 24, 2006
Posted by takeuaway in Basic Perl, chapter 1.add a comment
The -e Switch
Executes perl statements at command prompt instead of from a script file.
e.g perl -e “print ‘hello dolly’”;
The -c Switch
Checks the syntax of the perl script without actually executing the Perl commands. If the syntax is correct, Perl will tell you so.
e.g. perl -c hello.pl
The -w Switch
Warns user about possibility of using future reserved words.
e.g try_w_switch.pl
#!C:/Perl/Bin/Perl
print STDOUT ellie, “\tThe price is \$100.00\n”;
If i run it just using perl try_w_switch.pl, the output is :
ellie The price is $100.00
However, if i run it using perl -w try_w_switch.pl, i get the following output:
Unquoted string “ellie” may clash with future reserved word at try_w_switch.pl line 2.
ellie The price is $100.00
Btw, the print STDOUT …. is just another way to print text to the standard output, only with this type of command can i use the comma sign.
A “\t” indicates a tab character.
A “\n” indicates a new line character.
A “\” is neccessary before the “$” sign, else the output will be incorrect. This is because the “$”,”@” and “%” signs are special character prefix for variables.
#1 – Hello World July 24, 2006
Posted by takeuaway in Basic Perl, chapter 1.add a comment
This is the first perl script to write.
—————————————–
#!C:/Perl/Bin/Perl
print “Hello World\n”;
#prints the words “hello world” with a leading next-line character
—————————————–
The first line must always start with the “shebang” character -”#!”, followed by the location of where your perl interpreter resides.
I am using windows, but i suggest to use the “/” instead of the “\” as the folder separator because next time if you write a perl script on the apache server, all the “\” folder separator must be changed to “/” for it to work propely.
The second line uses the print command to print the trailing text unto the standard output.
Note that except for the first line, all lines should end with a “;” to indicate the end of the line.
The 3rd line is a comment, it will not be executed. A comment is indicated by a “#” at the beginning.
Save the file as hello.pl and run perl hello.pl in the command prompt.

That’s it!