Osp Perl Document
Osp Perl Document
What is Perl?
Perl features:
1. Mission critical
3. Easily extendible
There are over 25,000 open source modules available from the
Comprehensive Perl Archive Network (CPAN).
4. Text manipulation
Perl includes powerful tools for processing text that make it ideal
for working with HTML, XML, and all other mark-up and natural
languages.
5. Unicode support
6. Database integration
8. Embeddable
9. Open Source
Advantages of Perl:
Disadvantages of Perl:
Programming in Perl:
• Since the Perl is a lot similar to other widely used languages
syntactically, it is easier to code and learn in Perl.
• Programs can be written in Perl in any of the widely used text
editors like Notepad++, gedit etc.
• After writing the program save the file with the
extension .pl or .PL
• To run the program use perl file_name.pl on the command line.
Example:
Syntax:
# Single line comment
Example:
#!/usr/bin/perl
$b = 10; # Assigning value to $b
$c = 30; # Assigning value to $c
$a = $b + $c; # Performing the operation
print "$a"; # Printing the result
Example:
#!/usr/bin/perl
=Assigning values to
variable $b and $c
=cut
$b = 10;
$c = 30;
=Performing the operation
and printing the result
=cut
$a = $b + $c;
print "$a";
PERL OVERVIEW
❖ According to Wall, Perl has two slogans.
❖ The first is "There's more than one way to do it," commonly known as TMTOWTD.
❖ The second slogan is "Easy things should be easy and hard things should be possible".
OVERVIEW
❖ Features
❖ Design
❖ Appilication
❖ Implementation
❖ Availability
❖ Database interfaces
❖ Comparative performance
❖ Optimizing
FEATURES
❖ The overall structure of Perl derives broadly from C.
❖ Perl is procedural in nature, with variables ,expressions,assignment statements, brace-
delimited blocks, control structures,
subroutines.
❖ Perl also takes features from shell programming.
❖ All variables are marked with leading sigils, which allow variables
to be interpolated directly into strings.
❖ Perls database integration interface DBI supports third-party
databases including Oracle, Sybase, Postgres, MySQL and others.
❖ Perl works with HTML, XML, and other mark-up languages.
❖ Perl supports Unicode.
❖ Perl supports both procedural and object-oriented programming.
❖ Perl interfaces with external C/C++ libraries through XS or SWIG.
❖ Perl is extensible. There are over 20,000 third party modules available from the
Comprehensive Perl Archive Network (CPAN).
❖ The Perl interpreter can be embedded into other systems..
Design
❖ The design of Perl can be understood as a response to
three broad trends in the
computer industry: falling hardware costs, rising labor
costs, and improvements in compiler technology.
❖ Many earlier computer languages, such as Fortran and C,aimed to make efficient use
of expensive computer hardware.
❖ In contrast, Perl was designed so that computer programmers could write programs
more quickly and easily.
❖ Perl does not enforce any particular programming paradigm (procedural, object-
oriented, functional, or others) or even require the programmer to choose among
them.
❖ No written specification or standard for the Perl language exists for Perl versions
through Perl 5, and there are no plans to create one for the current version of Perl.
❖ There has been only one implementation of the interpreter, and the language has
evolved along with it.
❖ Perl has many features that ease the task of the programmer at the expense of
greater CPU and memory requirements.
❖ These include automatic memory management; dynamic typing; strings, lists, and
hashes; regular expressions; introspection; and an eval() function.
Application
❖ Perl has many and variety applications, compounded by the availability of many
standard and third-party modules.
❖ Perl has chiefly been used to write CGI scripts: large projects written in Perl
include cPanel, Slash, Bugzilla, RT, TWiki,
❖ It is also an optional component of the popular LAMP technology stack for Web
development, in lieu of PHP or Python.
❖ Perl is used extensively as a system programming language in the Debian GNU/Linux
distribution.[81]
❖ The combination makes Perl a popular all-purpose language for system administrators,
particularly because short programs, often called "one-liner programs," can be entered
and run on a single command line.
❖ Perl code can be made portable across Windows and Unix; such code is often used by
suppliers of software to simplify packaging and maintenance of software build- and
deployment-scripts
Perl is available on a wide variety of platforms −.
❖ For example, Perl/Tk and wxPerl are commonly used to enable user interaction with
Perl scripts. Such interaction may be synchronous or asynchronous, using callbacks to
update the GUI.
Implementation
❖ Perl is implemented as a core interpreter, written in C,together with a large collection
of modules, written in Perl and C.
❖ The interpreter has an object-oriented architecture. All of the elements
of the Perl language scalars, arrays, hashes, coderefs, file handlesare representent in
the interpreter by C structs.
❖ The life of a Perl interpreter divides broadly into a compile phase and a run phase. [83]
❖ In Perl, the phases are the major stages in the interpreter's life-cycle. Each interpreter
goes through each phase only once, and the phases follow in a fixed sequence.
❖ Perl is distributed with over 250,000 functional tests for core Perl
language.
Availability
❖ Perl is dual licensed under both the Artistic License 1.0 and
the GNU General Public License.[6] Distributions are available for
most operating systems. It is particularly prevalent
on Unix and Unix-like systems, but it has been ported to most
modern (and many obsolete) platforms.
❖ Because of unusual changes required for the classic Mac
OS environment, a special port called MacPerl was shipped
independently.[89
❖ The Comprehensive Perl Archive Network carries a complete
list of supported platforms with links to the distributions
available on each.
Optimizing
❖ Because Perl is an interpreted language, it can give
problems when efficiency is critical; in such situations, the
most critical routines can be written in other languages (such
as C), which can be connected to Perl via simple In line
modules or the more complex but flexible XS mechanism.
Database interfaces
❖ Perl's text-handling capabilities can be used for
generating SQL queries; arrays, hashes, and automatic
memory management make it easy to collect and process the
returned data In Perl 5, database interfaces are implemented
by Perl DBI modules.
❖ The DBI (Database Interface) module presents a single,
database independent interface to Perl applications, while the
DBD (Database Driver) modules handle the details of
accessing some 50 different databases; there are DBD drivers
for most ANSI SQL databases.
Comparative performance
❖ The Computer Language Benchmarks compares the
performance of implementations of typical programming
problems in several programming languages.
❖ Large Perl programs start more slowly than similar programs in
compiled languages because perl has to compile the source
every time it runs.
❖ In a talk at the YAPC::Europe 2005 conference and
subsequent article "A Timely Start," Jean-Louis Leroy found
that his Perl programs took much longer to run than expected
because the perl interpreter spent significant time finding
modules within his over-large include path.
❖ Once Perl code is compiled, there is additional
overhead during the execution phase that typically is
not present for programs written in compiled languages
such as C or C++.[1
1. Scalars:
● It is a single unit of data which can be an integer number, floating point, a
character, a string, a paragraph, or an entire web page.
● They are preceded by a dollar sign ($).
Example:
# Perl Program to demonstrate the
# Scalars data types
# An integer assignment
$age = 1;
# A string
$name = "ABC";
# A floating point
$salary = 21.5;
# displaying result
print "Age = $age\n";
print "Name = $name\n";
print "Salary = $salary\n";
Output:
Age = 1
Name = ABC
Salary = 21.5
● Scalar Operations:
− There are many operations which can be performed on the scalar
data types like addition, subtraction, multiplication etc.
Example:
# Perl Program to demonstrate
# the Scalars operations
#!/usr/bin/perl
# Concatenates strings
$str = "GFG" . " is the best";
# adds two numbers
$num = 1 + 0;
# multiplies two numbers
$mul = 4 * 9;
# concatenates string and number
$mix = $str . $num;
# displaying result
print "str = $str\n";
print "num = $num\n";
print "mul = $mul\n";
print "mix = $mix\n";
Output:
str = GFG is the best
num = 1
mul = 36
mix = GFG is the best1
2. Arrays:
● An array is a variable that stores the value of the same data type in the
form of a list.
● To declare an array in Perl, we use ‘@’ sign in front of the variable
name.
Example:
@age=(10, 20, 30)
It will create an array of integers which contains the value 10, 20 and 30. To
access a single element of an array, we use the ‘$’ sign.
$age[0]
It will produce the output as 10.
Example:
Output:
$ages[0] = 33
$ages[1] = 31
$ages[2] = 27
$names[0] = Geeks
$names[1] = for
$names[2] = Geeks
3. Hashes(Associative Arrays):
● It is a set of key-value pair.
● It is also termed as the Associative Arrays.
● To declare a hash in Perl, we use the ‘%’ sign. To access the particular
value, we use the ‘$’ symbol which is followed by the key in braces.
Example:
#!/usr/bin/perl
%data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40);
print "\$data{'John Paul'} = $data{'John Paul'}\n";
print "\$data{'Lisa'} = $data{'Lisa'}\n";
print "\$data{'Kumar'} = $data{'Kumar'}\n";
Perl Variables:
● Variables in Perl are used to store and manipulate data throughout the
program.
● When a variable is created it occupies memory space.
● The data type of a variable helps the interpreter to allocate memory and
decide what to be stored in the reserved memory.
● Therefore, variables can store integers, decimals, or strings with the
assignment of different data types to the variables.
Naming of a Variable:
A variable in Perl can be named anything with the use of a specific
datatype. There are some rules to follow while naming a variable:
● Variables in Perl are case sensitive.
Example:
$John and $john are two different variables
● It starts with $, @ or % as per the datatype required, followed by zero or
more letters, underscores and digits
● Variables in Perl cannot contain white spaces or any other special character
except underscore.
Example:
$my-name = "John"; // Invalid
$my name = "John"; // Invalid
$my_name = "John"; // Valid
Declaration of a Variable
Variable Declaration is done on the basis of the datatype used to define the
variable. These variables can be of three different datatypes:
● Scalar Variables: It contains a single string or numeric value. It starts with
$ symbol.
Syntax: $var_name = value;
Example:
$item = "Hello"
$item_one = 2
● Array Variables: It contains a randomly ordered set of values. It starts
with @ symbol.
Syntax : @var_name = (val1, val2, val3, …..);
Example:
@price_list = (70, 30, 40);
@name_list = ("Apple", "Banana", "Guava");
● Hash Variables: It contains (key, value) pair efficiently accessed per key.
It starts with % symbol.
Syntax : @var_name = (val1 = key1, val2 = key2, val3 = key3, …..);
Example:
%item_pairs = ("Apple" =>2, "Banana'=>3);
%pair_random = ("Hi" =>8, "Bye"=>9);
Modification of a Variable
Perl allows to modify its variable values anytime after the variable declaration is
done. There are various ways for the modification of a variable:
● A scalar variable can be modified simply by redefining its value.
Example:
$name = "John";
# This can be modified by simply
# redeclaring the variable $name.
$name = "Rahul";
● An element of an array can be modified by passing the index of that
element to the array and defining a new value to it.
Example:
@array = ("A", "B", "C", "D", "E");
# If value of second variable is to
# be modified then it can be done by
@array[2] = "4";
# This will change the array to,
# @array = ("A", "B", "4", "D", "E");
● A value in a hash can be modified by using its Key.
Example:
%Hash = ("A", 10, "B", 20, "C", 30)
# This will modify the value
# assigned to Key 'B'
$Hash{"B"} = 46;
%Hash = (“A”, 10, ”B”, 46, ”C”, 30)
Variable Interpolation:
● Perl provides various methods to define a String to a variable.
● This can be done with the use of single quotes, double quotes, using q-
operator and double-q operator, etc.
● Using single quotes and double quotes for writing strings is same but
there exists a slight difference between how they work.
● Strings which are written with the use of single quotes display the content
written within it exactly as it is.
Example:
$name = "John"
print 'Hi $name\nHow are you?'
The above code will print:
Hi $name\nHow are you?
Whereas strings written within double quotes replace the variables with their
value and then displays the string. It even replaces the escape sequences by their
real use.
Example:
$name = "John"
print "Hi $name\nHow are you?"
The above code will print:
Hi John
How are you?
Example Code:
#!/usr/bin/perl
use Data::Dumper;
# Scalar Variable
$name = "GeeksForGeeks";
# Array Variable
@array = ("G", "E", "E", "K", "S");
# Hash Variable
%Hash = ('Welcome', 10, 'to', 20, 'Geeks', 40);
# Variable Modification
@array[2] = "F";
print "Modified Array is @array\n";
# Interpolation of a Variable
# Using Single Quote
print 'Name is $name\n';
# Using Double Quotes
print "\nName is $name";
# Printing hash contents
print Dumper(\%Hash);
Output:
Modified Array is G E F K S
Name is $name\n
Name is GeeksForGeeks$VAR1 = {
'to' => 20,
'Welcome' => 10,
'Geeks' => 40
}
Operators:
Relational operators:
• Relational operators are operators that compare two expressions.
• In math we use operators like >, <, and ≠ to compare numeric
expressions.
• There are six numeric relational operators in Perl, which are listed in
the next slide.
Logical operators:
The following are logical operators in Perl:
1 if statement
2 if...else statement
An if statement can be followed by an optional else statement.
3 if...elsif...else statement
An if statement can be followed by an optional elsif statement and then by an
optional else statement.
4 unless statement
An unless statement consists of a boolean expression followed by one or more
statements.
5 unless...else statement
An unless statement can be followed by an optional else statement.
6 unless...elsif..else statement
An unless statement can be followed by an optional elsif statement and then by
an optional else statement.
7 switch statement
With the latest versions of Perl, you can make use of the switch statement. which
allows a simple way of comparing a variable value against various conditions.
1.The if statement:-
➢ If the boolean expression evaluates to true then the block of code inside
the if statement will be executed.
➢ If boolean expression evaluates to false then the first set of code after the
end of the if statement (after the closing curly brace) will be executed.
Flow Diagram:
Syntax:
If(expression)
{ statement1;
Statement2;…
}
Example:
$a = 1;
if($a == 1)
2.If-else statement:
Perl provides the if else statement that allows you to execute a
➢
code block if the expression evaluates to true , otherwise, the
code block inside the else branch will execute.
Flow chart:
Syntax:
if(expression){
}else{
Example:
$a = 1;
$b = 2;
if($a == $b){
print("a and b are equal\n");
}else{
3.if...elsif...else statement:
Flow chart:
Syntax
if(expression){
...
}elsif(expression2){
...
}elsif(expression3{
...
}else{
...
}
Example:
$a = 1;
$b = 2;
if($a == $b){
}else{
4.unless statement:
Perl executes the statement from right to left, if the condition is
➢
Syntax:
unless(condition){
// code block
}
Example:
$a = 10;
5.unless...else statement:
➢ Similar to unless statement, the unless-else statement in Perl behaves
opposite to the if-else statement.
➢ In unless-else, the statements inside unless gets executed if the
condition is false and statements inside else gets executed if the
condition is true.
Flow chart:
Syntax:
unless(condition){
}else{
}
Example:
$a = 10;
}else{
Syntax:
unless(condition_1){
}elsif(condition_2){
}else{
Example:
#!/usr/local/bin/perl
$a = 20;
unless( $a == 30 ) {
} elsif( $a == 30 ) {
# if condition is true then print the following
} else {
7.Switch statement:
➢ A switch statement allows a variable to be tested for equality
against a list of values.
➢ Each value is called a case, and the variable being switched on is
checked for each switch case.
Flow Diagram:
Syntax:
given(expression)
{
when ( first value)
{
statement to be executed;
}
when (second value)
{
statement to be executed;
}
....
...
when (nth value)
{
statement to be executed;
}
default
{
statement to be executed if all the cases are not matched.;
}
}
Example:
use feature qw(switch say);
print "Enter the Number for the Week \n";
chomp( my $week = <> );
given ($week)
{
when('1')
{
say "Monday";
}
when('2')
{
say "Tuesday";
}
when('3')
{
say "Wednesday";
}
when('4')
{
say "Thursday";
}
when('5')
{
say "Friday";
}
when('6')
{
say "Saturday";
}
when('7')
{
say "Sunday";
}
default
{
say "Please Enter valid Week Number";
}
}
Loops
Looping in programming languages is a feature which facilitates the execution of a set
of instructions or functions repeatedly while some condition evaluates to true. Loops make
the programmers task simpler. Perl provides the different types of loop to handle the
condition based situation in the program. The loops in Perl are :
• for loop
• foreach loop
• while loop
• do…. while loop
• until loop
• Nested loops
for Loop
“for” loop provides a concise way of writing the loop structure. A for statement consumes
the initialization, condition and increment/decrement in one line thereby providing a shorter,
easy to debug structure of looping.
Syntax:
for (init statement; condition; increment/decrement )
{
# Code to be Executed
}
Flow Chart:
Example :
# for loop
for ($x =10; $x<=15 ; $x++)
{
print "$x\n"
}
Output:
10
11
12
13
14
15
foreach Loop
A foreach loop is used to iterate over a list and the variable holds the value of the
elements of the list one at a time. It is majorly used when we have a set of data in a list and
we want to iterate over the elements of the list instead of iterating over its range. The process
of iteration of each element is done automatically by the loop.
Syntax:
foreach variable
{
# Code to be Executed
}
Flow Chart:
Example:
# Array
@data = ('GEEKS', 'FOR', 'GEEKS');
# foreach loop
foreach $word (@data)
{
print $word
}
Output:
GEEKSFORGEEKS
while Loop
• A while loop generally takes an expression in parenthesis.
• If the expression is True then the code within the body of while loop is executed.
• It is also known as a entry controlled loop as the condition is checked before
executing the loop.
Syntax :
while (condition)
{
# Code to be executed
}
Flow Chart:
Example :
# while loop
$count = 3;
while ($count >= 0)
{
$count = $count - 1;
print "GeeksForGeeks\n";
}
Output:
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
Infinite While Loop: While loop can execute infinite times which means there is no
terminating condition for this loop. In other words, we can say there are some conditions
which always remain true, which causes while loop to execute infinite times or we can say it
never terminates.
Syntax:
do {
# statments to be Executed
} while(condition);
Flow Chart:
Example :
$a = 10;
# do..While loop
do {
until loop
• until loop is the opposite of while loop. It takes a condition in the parenthesis and it
only runs until the condition is false.
• Basically, it repeats an instruction or set of instruction until the condition is FALSE.
• It is also entry controller loop i.e. first the condition is checked then set of instructions
inside a block is executed.
Syntax:
until (condition)
{
# Statements to be executed
}
Flow Chart:
Example :
# Perl program to illustrate until Loop
$a = 10;
# until loop
until ($a < 1)
{
print "$a ";
$a = $a - 1;
}
Output:
10 9 8 7 6 5 4 3 2 1
Nested Loops
A nested loop is a loop inside a loop. Nested loops are also supported by Perl Programming.
Syntax for while nested loop in Perl:
$a=5;
#outer while loop
while($a>0)
{
$b=1;
#inner while loop
while($b<=$a)
{
print "*";
$b=$b+1;
}
$a=$a-1;
print "\n”;
}
Output:
*****
****
***
**
*
PERL SUBROUTINES
Definition
• A Perl function or subroutine is a group of statements that together perform
a specific task.
• In every programming language user want to reuse the code.
• So the user puts the section of code in function or subroutine so that there
will be no need to write code again and again.
• In Perl, the terms function, subroutine, and method are the same but in
some programming languages, these are considered different.
• The word subroutines is used most in Perl programming because it is
created using keyword sub.
• Whenever there is a call to the function, Perl stop executing all its program
and jumps to the function to execute it and then returns back to the section
of code that it was running earlier.
In versions of Perl before 5.0, the syntax for calling subroutines was slightly
different as shown below. This still works in the newest versions of Perl.
Let's have a look into the following example, which defines a simple function
and then call it. Because Perl compiles your program before executing it, it doesn't
matter where you declare your subroutine.
#!/usr/bin/perl
# Function definition
sub Hello {
print "Hello, World!\n";
}
# Function call
Hello();
When above program is executed, it produces the following result −
Hello, World!
#!/usr/bin/perl
# Function definition
sub rectangle
{
$area=@_[0]*@_[1];
$perimeter=2*(@_[0]+@_[1]);
print "Area of the rectangle is: $area
sq.units\n";
print "Perimeter of the rectangle is: $perimeter
units\n";
}
# Function call
rectangle(10, 20);
Output
Area of the rectangle is: 200 sq.units
Perimeter of the rectangle is: 60 units
#!/usr/bin/perl
# Function definition
sub random
{
@hobbies=@_;
print "Hobbies: @hobbies\n";
}
@favs=("Playing Guitar","Playing Chess","Reading
Books");
# Function call with list parameter
random(@favs);
When above program is executed, it produces the following result –
Hobbies: Playing Guitar Playing Chess Reading Books
#!/usr/bin/perl
# Function definition
sub PrintHash {
my (%hash) = @_;
#!/usr/bin/perl
# Function definition
sub circle
{
$radius=@_[0];
return 3.14*$radius*$radius;
}
# Function call
$area=circle(10);
print "The area of the circle is $area sq. units\n";
When above program is executed, it produces the following result −
The area of the circle is 314 sq.units
#!/usr/bin/perl
# Global variable
$var=500;
# Function definition
sub test {
# Private variable
my $var=50;
print "Value of variable inside the subroutine
$var\n";
}
# Function call
test();
print "Value of variable outside the subroutine
$var\n";
package Foo;
# This is Foo package
$i = 10;
print "Package name : " , __PACKAGE__ , " $i\n";
package main;
# This is again main package
$i = 100;
print "Package name : " , __PACKAGE__ , " $i\n";
print "Package name : " , __PACKAGE__ , " $Foo::i\n";
1;
OUTPUT:
Package name : main 1
Package name : Foo 10
Package name : main 100
Package name : main 10
package Foo;
print "Begin and Block Demo\n";
BEGIN {
print "This is BEGIN Block\n"
}
END {
print "This is END Block\n"
}
1;
OUTPUT:
This is BEGIN Block
Begin and Block Demo
This is END Block
The first thing comes to your mind is the module name e.g., FileLogger. The
main functionality of the FileLogger module is to:
1. First, create your own module name, in this case, you call it FileLogger.
2. Second, create a file named modulename.pm. In this case, you need to
create a new file named FileLogger.pm. pm stands for Perl module.
3. Third, make the FileLogger module a package by using the
4. Fourth, write the code for subroutines and variables, and put the code
into the FileLogger.pm file.
5. Fifth, put the last statement in the FileLogger.pm file: 1; to make the file
returns true.
sub open{
my $logfile = shift;
# open log file for appending
open(LFH, '>>', $logfile) or die "cannot open the log file $logfile: $!";
# write time:
print LFH "Time: ", scalar(localtime), "\n";
}
We need another subroutine to append log messages to the log file. We only log
messages if the input log level is lower than the current module’s log level. We
use print() function to write log messages into the log file.
sub log{
my($log_level,$log_msg) = @_;
if($log_level =~ /^\d+$/){
$LEVEL = $log_level;
}
}
Fifth, at the end of the FileLogger.pm file, we put the statement: 1;
Example:
➢ A Perl module file called Foo.pm might contain statements like this.
#!/usr/bin/perl
package Foo;
sub bar {
print "Hello $_[0]\n"
}
sub blat {
print "World $_[0]\n"
}
1;
#!/usr/bin/perl
require Foo;
Foo::bar( "a" );
Foo::blat( "b" );
You must have noticed that the subroutine names must be fully qualified to call
them. It would be nice to enable the subroutine bar and blat to be imported into
our own namespace so we wouldn't have to use the Foo:: qualifier.
#!/usr/bin/perl
use Foo;
bar( "a" );
blat( "b" );
Notice that we didn't have to fully qualify the package's function names.
The use function will export a list of symbols from a module given a few added
statements inside a module.
require Exporter;
@ISA = qw(Exporter);
Then, provide a list of symbols (scalars, lists, hashes, subroutines, etc) by filling the
list variable named @EXPORT: For Example −
package Module;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(bar blat);
use strict;
use warnings;
#using package p
use ab::p;
#Function Hello of p
p::Hello();
Opening files:-
To read or write files in perl you need to open a file handle. File
handles in perl are yet another kind of variable. They act as conversion
reference(handles, if you will) between your program and the operating system
about a particular file. They contain information about how the files was opened
and how far along you are in reading (or writing) the file they also contain user-
definable attributes about how the file is to be read or write
Any time you need to access a file on your disk. You need to create
a new file handled and prepare it by operating the file handled. You open file
handled. Not surprisingly, with the open function. They syntax of open function
is as follows:
Reading:-
You can read from perl’s file handling in a couple of different ways. The
most common method is to use the file input operator also called the angle
operator(<>). To read a file handle, simply put the file handle name inside the
angle operator and assign the value to a variable.
Writing:-
To write data to a file, you must first have a file-handle open for writing.
Up till now, all open statements you have seen have opened the file handle for
reading only. The syntax for opening a file for writing is almost identical to that
for reading.
❖ -e-command
❖ the diamond operator
❖ n and p ; automatic looping power houses
❖ l: line -ending handling
❖ -i: edit in place
❖ -o[octal]:specify input-record separator
-e command:
• The most useful way to use the command-line options is writing perl one-liners right
in the shell.
• e e-option is the basis for most command-line programs.
• It accepts the value of the parameter as the source text for a program.
• Since this is a single statement in a block, you can omit the semicolon.
• When e-option is uses, perl no longer looks for a program name on the command
line.
$perl-e print “hello,world ! \n “