Q. I’m new to Linux and Perl. I’ve printed perl man page but it is bit confusing and omits a lot of simple things or details. Can you tell me how do I write a perl script? How do I open perl editor?
A. Larry Wall began work on Perl in 1987 and it is a dynamic programming language. Traditionally perl programs are written using text editor such as vi or emacs. The overall structure of Perl derives broadly from C.
Also when you start learning a new programming language, always start with Hello world program.
Hello world Perl Program
Let us print Hello world from a shell prompt. Type the following command (excluding $ ):
$ perl -e 'print "Hello, world!\n"';
Let us write hello world program using vi text editor:
$ vi hello.pl
Append code as follows:
print "Hello, world!\n";
Save and close the file. Now setup a execute permission:
$ chmod +x hello.pl
Finally execute perl program:
- First, I used the vi command to create a file named hello.pl
- The first line of the script used to specify that the script is to be executed by perl program (#!/usr/bin/perl) and not by a shell.
- Print command prints hello world on screen. Please note that the notation \n which stands for newline i.e. print a newline.
This is just a simple introduction. You should consider following text books & resources for more information and mastering the perl:
- Beginning Perl, Second Edition by James Lee
- Learning Perl - by Randal L. Schwartz, Tom Phoenix, brian d foy. O'Reilly Media, Inc.
- 30 Cool Open Source Software I Discovered in 2013
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop