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
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..
|
|
|
![]() |
|
| <Send This Link to a Friend> <Bookmark This Page> | ||