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.
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 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:
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
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
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
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.
© Copyright 2021. All Rights Reserved.