Fast Track Programming in Perl

In Windows give the command in the Command prompt terminal,

C:\perl -e "print \"Hello World!\n\"; " (enclosed inside double quotes)

In Linux platforms,

$perl -e 'print "Hello world\n" ' (enclosed inside both single and double quotes)

In Windows, open NotePad, type the following line:

print "Hello world\n";

save it as a file 'filename'.

Then run from command prompt as

C:\perl filename (this will execute perl commands from the file 'filename')

Save the following five lines in file and run as perl filename

#Two lines to output the local time
$now = time();
print "The local time is ", scalar(localtime($now)), "\n";
#To output the GMT
print "Greenwich mean time is ", scalar(gmtime($now)), "\n";

C:\perl -c filename (compiles but does not execute, lists the errors in the program)

C:\perl -wc filename (compiles and turns on warnings too, along with error reporting)

C:\perl -h (lists the possible options available in the installation)

To sort a set of input words from command prompt save these two lines in a file:

@sorted = sort @ARGV;
print "Sorted: @sorted.\n";

Run the program as
C:\perl filename word1 word2 word3

The words will be stored in
$sorted[0],
$sorted[1];
$sorted[2];

Thus, you can also print only selected words after sorting.

The print command is useful in generating desirable outputs. Save each of these programs in a file and run. The EOF control is a special marker to print content as prescribed.

#program 1
print << EOF
Hi! This is a whole paragraph!
I am learning Perl and it sounds cool!
EOF

#program 2
print << EOF
<HTML><HEAD><TITLE>My First Web Page<TITLE><HEAD>
<BODY>Welcome to my home page!\<BODY>
</HTML>
EOF

Go to perl-page 4 ... Back to perl-page 2 ... Starting page