Perl By Example
Version: 1.0.2
Date: 7th March 2006
Outputting Text
Here is my version of the classic 'Hello World' program.
#!/usr/bin/perl # # ==================== # Hello World Program # ==================== # Purpose: Print 'Hello World' on the screen. # Author: Eddie Meyer # Date: 01 FEB 2006 print "Hello World\n";
Find Out How Many Command Line Arguments Were Provided To Your Program
The following program prints out the number of command line arguments that were supplied to your Perl script.
#!/usr/bin/perl # ================================= # Number Of Command Line Arguments # ================================= # Purpose: Program to determine the number of command line arguments that were given # to this script. # Author: Eddie Meyer # Date: 7th March 2006 # Command line arguments are automatically supplied to your program via the @ARGV # array. Here's how you get the size of the array... $num_arguments = @ARGV; print "Number of command line arguments was $num_arguments.\n"; # Additional Note: You can use the @ARGV array just like any other perl array. # For instance, to access the first command line argument, simply use something like... # $arg_one = $ARGV[0]; # Remember that perl arrays are zero based, just like many other programming languages.
Calling An External Program
You can call an external program using either the exec or system commands. The difference between the two is that your program will terminate after a call to exec, whereas, with the system command, your program will continue as normal as soon as the external program has finished running.
#!/usr/bin/perl
#
# =============================
# Calling An External Program
# =============================
# Purpose: To illustrate using the 'system' function to call an external program.
# Author: Eddie Meyer
# Date: 01 FEB 2006
system("clear");
Please come back soon for more.
-- Eddie.
Copyright © 2006 Eddie Meyer
