- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Perl First 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";
- Related Articles
- First CGI Program using Perl
- How to run Perl Program?
- The First IOT Program
- First CGI Program in Python
- Perl File Extension
- Comments in Perl
- Whitespaces in Perl
- Perl Scalar Variables
- Perl Array Variables
- Perl Hash Variables
- Perl Variable Context
- Perl Numeric Scalars
- Perl String Scalars
- Perl Special Literals
- Understanding Perl Array
