Like any other programming language Perl also has various operators for different
mathematical, lexical, logical operations.
The broad categories or Perl operators are.
· Arithmetic Operators
· Assignment Operators
· Numeric Comparison
· String Comparison
· Logical Operators
Arithmetic Operators
Operator Function
+ Addition
-
Subtraction, Negative Numbers, Unary
Negation
* Multiplication
/ Division
% Modulus
** Exponent
List of Arithmetic Operators in Perl
Like any other programming language the above operators perform operations indicated
by their name.
Example1
The total revenue of a web portal could be.
$cost=20;
$profit=10;
$net_profit=$profit-$cost;
Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts
First PERL Program
Lets create a first.pl and type the following text
#!/usr/local/bin/perl
print “Hello Pratap\n”;
The first line tells the program where to pick the interpreter to execute the rest of the code
in the file.
The print command is a PERL in built function to print the text following by the print
word to the standard output.
Save the file and close. Allow executable permissions and then run the program. You
would see a nice text “Hello Pratap” printed on your screen.
Perl Introduction
PERL Evolution
PERL stands for Practical Extraction and Report Language.
PERL was first developed by Larry Wall, a linguist working as a systems administrator
for NASA in the late 1980s, as a way to make report processing easier. Since its
invention PERL has grown significantly and is used popularly in automated processes
and an interface between different computer systems and a popular interface for CGI
programming in web.
PERL was a most convenient option for those comfortable with C programming for its
closeness to the syntaxes of C. Perl was originally designed for text processing and that’s
precisely the reason that it is the most popular language to be used for web applications.
PERL – Interpreted Language
Every PERL program is executed by a PERL interpreter which usually resides in
/usr/local/bin or /usr/bin directory in UNIX systems. The first line of a PERL program
usually contains the PERL interpreter to be used to execute that program (#! line). This is
useful if your machine has multiple versions of PERL installed.
#!/usr/local/bin/perl
PERL interpreter compiles the program internally into a parse tree and then executes it
immediately. Perl is commonly known as an interpreted language, but this is not strictly
true. Since the interpreter actually does convert the program into byte code before
executing it, it is sometimes called an interpreter/compiler.
Structure of PERL program
PERL programs contain a serious of statements with a first line indicating the interpreter
to be used to execute the program. All statements end with a semicolon. The statements
use PERL in-built functions and also user defined subroutines. It is straight forward and
doesn’t require a main() block like C.
PERL stands for Practical Extraction and Report Language.
PERL was first developed by Larry Wall, a linguist working as a systems administrator
for NASA in the late 1980s, as a way to make report processing easier. Since its
invention PERL has grown significantly and is used popularly in automated processes
and an interface between different computer systems and a popular interface for CGI
programming in web.
PERL was a most convenient option for those comfortable with C programming for its
closeness to the syntaxes of C. Perl was originally designed for text processing and that’s
precisely the reason that it is the most popular language to be used for web applications.
PERL – Interpreted Language
Every PERL program is executed by a PERL interpreter which usually resides in
/usr/local/bin or /usr/bin directory in UNIX systems. The first line of a PERL program
usually contains the PERL interpreter to be used to execute that program (#! line). This is
useful if your machine has multiple versions of PERL installed.
#!/usr/local/bin/perl
PERL interpreter compiles the program internally into a parse tree and then executes it
immediately. Perl is commonly known as an interpreted language, but this is not strictly
true. Since the interpreter actually does convert the program into byte code before
executing it, it is sometimes called an interpreter/compiler.
Structure of PERL program
PERL programs contain a serious of statements with a first line indicating the interpreter
to be used to execute the program. All statements end with a semicolon. The statements
use PERL in-built functions and also user defined subroutines. It is straight forward and
doesn’t require a main() block like C.
Searching for a specific file name and deleting all instances of that.
#!/usr/bin/perl -w
use strict;
use File::Find;
sub wanted {
# Check to see if the filename is not a directory
if ( -f $File::Find::name ) {
# Verify the filename eds in .tmp
if ( $File::Find::name=~/\.test.txt$/i) # Give the file name you want to delete
{
print “Removing $File::Find::name\n”;
unlink $File::Find::name;
}
}
}
find(\&wanted, ‘d://Test’); # Give the path from where you want to delete the files
Subscribe to:
Posts (Atom)