Perl Basic Syntax
Perl Basics – Part 2
Perl Course
Foreword: In this part of the series, I give you the basic syntax of Perl.
By: Chrysanthus Date Published: 29 Mar 2015
Introduction
Statement
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.
Comments
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.
Comment Example
Type the following in a blank page of a text editor:
use strict;
#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:
comment.pl
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.
String
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.
Chrys
Related Links
Perl BasicsPerl Data Types
Perl Syntax
Perl References Optimized
Handling Files and Directories in Perl
Perl Function
Perl Package
Perl Object Oriented Programming
Perl Regular Expressions
Perl Operators
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
Perl Scoping
Namespace in Perl
Perl Eval Function
Writing a Perl Command Line Tool
Perl Insecurities and Prevention
Sending Email with Perl
Advanced Course
Miscellaneous Features in Perl
Perl Two-Dimensional Structures
Advanced Perl Regular Expressions
Designing and Using a Perl Module
More Related Links
Perl Mailsend
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library
MySQL Course
BACK NEXT