Nov 23, 2006

Basic #2, Switches to Run Perl

-e Switch

Executes perl statements at command prompt instead of from a script file.
e.g perl -e “print ‘hello dolly’”;


-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.

No comments: