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