
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
First Perl Program
Interactive Mode Programming
You can use Perl interpreter with -e option at the command line, which lets you execute Perl statements from the command line. Let's try something at $ prompt as follows −
$perl -e 'print "Hello World\n"'
This execution will produce the following result −
Hello, world
Script Mode Programming
Assuming you are already on $ prompt, let's open a text file hello.pl using vi or vim editor and put the following lines inside your file.
Example
#!/usr/bin/perl # This will print "Hello, World" print "Hello, world\n";
Here /usr/bin/perl is actual the Perl interpreter binary. Before you execute your script, be sure to change the mode of the script file and give execution privilege, generally a set of 0755 works perfectly and finally you execute the above script as follows −
$chmod 0755 hello.pl $./hello.pl
Output
This execution will produce the following result −
Hello, world
You can use parentheses for functions arguments or omit them according to your personal taste. They are only required occasionally to clarify the issues of precedence. The following two statements produce the same result.
print("Hello, world\n"); print "Hello, world\n";