Perlaccess : Tutorials : Operators
Operators: Arithmetic (6.1)
by Brett Roberts
http://www.bigresources.com

Operators at a Glance
Operators make up the foundation of a perl script's comparison, logic, and arithmetic processing. I would say that 9 out of 10 scripts have operators in them. If you have taken any math class or any other kind of programming language then you will most likely be familiar with the many types of operators. Below, I will explain their functions in dealing with perl scripts.

Arithmetic Operators
Arithmetic Operators generally perform mathematical calculations on numbers. The key word here is numbers. Do not mistakenly use these types of operators when trying to combine strings...there are special operators for this purpose. The following table outlines the different arithmetic operators used widely in perl scripts:

+ Addition of two or more numbers
- Subtraction, Negative Numbers, Unary Negation
* Multiplication of two or more numbers
/ Division of two or more numbers
** Exponential
% Modulus


There would obviously be many uses for these types of operators in today's world, ranging from accounting packages to a simple web site counter... below is some sample code to get your feet wet:

# This calculation will find total web page visits for 1
# year assuming we know each months' visits

$january=345;
$february=256;
$march=444;
$april=541;
$may=678;
$june=350;
$july=411;
$august=398;
$september=500;
$october=758;
$november=648;
$december=1555;


# To be safe...it would be wise to place the following
# statement all on 1 line in your code...

$total_visits=$january+$february+$march+$april+$may+$june+$july+
                   $august+$september+$october+$november+$december;