Linux Classes
Linux Training
* Linux Classes *

LINUX CLASSES - PERL PROGRAMMING

Perl - What Basics Should I Know?

Perl is an interpreted language that is very popular in the Unix community because it has a rich and powerful feature set, but is still easy to use. Perl borrows heavily from other languages such as C and awk and is especially useful for processing text, generating reports, and handling Common Gateway Interface (CGI) requests submitted via Web browsers.

Perl has been ported to many non-Unix environments, including DOS, OS/2, Macintosh, VMS, and Windows NT. The fact that a Perl program can run with little or no modification on many different platforms is another reason for its popularity. In this section, I'll introduce you to basics of Perl and point you to some resources where you can learn more.

Perl Basics

To create a Perl script, use a text editor to enter Perl commands, save the file with a .pl extension (such as sample.pl), and then use chmod to mark the file as executable. The extension is not required, but it's a common Unix convention and will help you identify your Perl source files without looking inside.

Here's a very simple Perl script:

#!/usr/bin/perl
print "I am here. \n";

The mysterious first line starting with "pound splat slash" is required for all Perl scripts to run; it tells the system where to find the Perl interpreter. Hopefully, you've already figured out that this program prints a message followed by the newline character.

Unlike the echo command in Bash scripts, Perl's print command doesn't automatically send a carriage return and line feed. If you forget the \n sequence, the next print command will start on the same line. Also note that all Perl statements must end with a semicolon.

Previous Lesson: Shell Script Debugging
Next Lesson: Perl Variables

[ RETURN TO INDEX ]

Comments (most recent first)

shirish     (15 Aug 2010, 15:03)
hi this shirish shukla from india
am just completd RHCE exam with 100%
I need your help for understanding
perl scripting from base
would be great if you coluld sent me any pdf or any files hat started from base of learning..

Thanks
Shirish
G     (04 Aug 2010, 15:10)
exactly what I was looking for, thanks.
Bob Rankin     (06 Apr 2010, 07:36)
You could enter:
perl example.pl
Or make sure it's executable with the command:
chmod a+rx example.pl
Then you can run it just by typing:
example.pl
A.Kamel     (03 Apr 2010, 11:37)
Could you notify How to run script after create it as $./example.pl
prashant     (19 Mar 2010, 04:11)
very good disciption about all the things...nice one...thnku..

*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 

Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.