Doctor Bob
Linux Topic Search
TOURBUS
HOME PAGE
SAVVY
CONSUMER
FREE TECH
SUPPORT

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

No comments yet

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