Cyber Sentry
Application Development
System Architecture Design
Technical Due Diligence
Qmail Support and Consultancy
Scripting Help
Partners
Client Testimonials
Help Sections
Software Patents
Site Map
Contact us
Community
Home

Operations and Assignment

Once we have declared variables, we can now perform comutations using them. To do this we need to look at a few operators. Perl uses all the usual C arithmetic operators:

 

$a = 1 + 2; # Add 1 and 2 and store in $a

$a = 3 - 4; # Subtract 4 from 3 and store in $a

$a = 5 * 6; # Multiply 5 and 6

$a = 7 / 8; # Divide 7 by 8 to give 0.875

$a = 9 ** 10; # Nine to the power of 10

$a = 5 % 2; # Remainder of 5 divided by 2

++$a; # Increment $a and then return it

$a++; # Return $a and then increment it

--$a; # Decrement $a and then return it

$a--; # Return $a and then decrement it

 

and for strings Perl has the following among others:

 

$a = $b . $c; # Concatenate $b and $c

$a = $b x $c; # $b repeated $c times

 

To assign values Perl includes

 

$a = $b; # Assign $b to $a

$a += $b; # Add $b to $a

$a -= $b; # Subtract $b from $a

$a .= $b; # Append $b onto $a

 

Note that when Perl assigns a value with $a = $b it makes a copy of $b and then assigns that to $a. Therefore the next time you change $b it will not alter $a.

 

You can find many more perl opperators on the perlop manual page. Type man perlop at the prompt.



Qmail Help Section
Perl Tutorial
Linux Command Line Help
Top top Copyright Cyber Sentry Ltd  

Cyber Sentry -- Application Development Sitemap 1 2 3