Perl Basic Syntax
Perl Basics – Part 2
Foreword: In this part of the series, I give you the basic syntax of Perl.
By: Chrysanthus Date Published: 29 Mar 2015
A statement in Perl is a short piece of code that ends with a semicolon. An example is:
print "Hello World!\n";
This statement displays or prints "Hello World!" without the quotes, at the console.
You should have comments in your code. Comments are not executed. Comments are to remind you later of why you typed a particular piece of code. In Perl, you generally have a comment in a single line; something like:
#This is a comment.
You begin each comment with the hash, # character. Your code is executed by the interpreter to perform a task, such as to print a piece of text. When the interpreter sees the # character, it ignores everything that is on its right. That is, it does not execute what is on the right of the # character.
Type the following in a blank page of a text editor:
#Talking about a man.
print "I am a man.\n";
#Talking about a boy.
print "He is a boy.\n";
Save the file as comment.pl in the root directory (C:\).
Start the console and use the cd c:\ command to go to the root, C:\> prompt. Then, type the following command and press the Enter Key:
The following should be printed:
I am a man.
He is a boy.
In the comment.pl script, you have two comments, which are “#Talking about a man.” and “#Talking about a boy.”. Since these are comments in the Perl code, they do not appear at the console. The Perl interpreter in the computer does not send them to the console.
If you see any text in double or single quotes in Perl code, that text is called a string. In this and the previous part of the series, you have seen strings only in double quotes. You have not yet seen strings in single quotes. You will see that soon.
Let us end here for this part of the series. We continue in the next part.
Related LinksPerl Basics
Perl Data Types
Perl References Optimized
Handling Files and Directories in Perl
Perl Object Oriented Programming
Perl Regular Expressions
Perl Core Number Basics and Testing
Commonly Used Perl Predefined Functions
Line Oriented Operator and Here-doc
Handling Strings in Perl
Using Perl Arrays
Using Perl Hashes
Perl Multi-Dimensional Array
Date and Time in Perl
Namespace in Perl
Perl Eval Function
Writing a Perl Command Line Tool
Perl Insecurities and Prevention
Sending Email with Perl
Miscellaneous Features in Perl
Perl Two-Dimensional Structures
Advanced Perl Regular Expressions
Designing and Using a Perl Module
More Related Links
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library