- Perl Basics
- Perl Home
- Perl Basic Syntax
- Perl Data Types
- Perl Variables
- Perl Scalars
- Perl Arrays
- Perl Hashes
- Perl If-Else
- Perl Loops
- Perl Operators
- Perl References
- Perl Subroutines
- Perl Formats
- Perl Date & Time
- Perl File I/O
- Perl Advanced
- Perl Directory
- Perl Regular Expressions
- Perl Special Variables
- Perl Socket Programming
- Perl Send E-mail
- Perl Object Oriented
- Perl Error Handling
- Perl CGI Programming
- Perl Database
- Perl Packages & Modules
- Perl Process Management
- Perl Test
- Perl Online Test
- Give Online Test
- All Test List
Perl Basic Syntax
Every perl program basically consists of sequence of declarations and statements. Every statement must end with semicolon. Let's start a program, prints "Hello Perl" to understand the basic syntax of a perl program.
#!/usr/bin/perl print("Hello Perl");
Here, /usr/bin/perl is the actual perl interpreter binary. Here is the sample output produced by the above perl program.
Hello Perl
A perl script can be created with any simple text editor. You can also download perl (like strawberry perl or EditRocket) from internet to run your perl script. A perl file must be saved with extension .pl in order to be recognized as functioning perl script.
Comments in Perl
Comments are line of texts which are ignored by the interpreter. Comments helps in debugging the code later. Comments also used in reviewing the code later. You can use comments to describe your code to understand the code later. There are the following two types of comments in perl:
- single line comment
- multiline comment
Single Line Comment in Perl
Everything start with hash (#) sign until the same line are considered to be a comment in perl. Here is an example of comment in perl
# i am a comment in perl
Multiline Comment in Perl
Lines starting with = sign are interpreted as the start of section of the embedded documentation, and all the subsequent lines until the next =cut, are all ignored by the perl interpreter. Here is an example of multiline comment in perl
=begin comment I am multiline comment in perl. This is multiline comment in perl. This is all part of multiline comment in perl. You can use multiline comment to describe your code expanded in multiline. Multiline comment in perl, helps in describing your code, in more than one line. =cut
Perl Comment Example
Here is an example of comment in perl. This perl program uses both single line and multiline comment in perl.
#!/usr/bin/perl # following will print Hello Perl print("Hello Perl\n"); =begin comment Following will print Hello Perl This is Perl Basic Syntax =cut print("\nHello Perl\nThis is Perl Basic Syntax");
Here is the sample output of the above Perl program:
Hello Perl Hello Perl This is Perl Basic Syntax
Perl Identifiers
An identifier in perl, is basically a name used to identify a variable, class, module, function, or any other object in perl program. Every perl variable name must start with either $, %, or @ followed by zero or more letters (a-z or A-Z), digits (0-9), underscores (_).
Note - Since, perl is a case sensitive language, therefore $Codescracker and $codescracker are two different identifiers in Perl.
« Previous Tutorial Next Tutorial »