Friday, June 5, 2009

Basic operations - Arithmatic & string

Code:


#!/usr/bin/perl
# Scaler Variables operations
$a=7;
$b=3;
$str1="abc";
$str2="def";

system (clear);
print "################## BASIC OPERATIONS IN PERL ################## \n";
print "\n\n#################### Arithmatic Operators #################### \n";

$c = $a + $b;
print "Addition \t\t\t: $a + $b = $c \n";

$d = $a * $b ;
print "Multiplication \t\t\t: $a * $b = $d \n";

$e = $a / $b ;
print "Division \t\t\t: $a / $b = $e \n";

$f = $a % $b;
print "Modulus \t\t\t: $a % $b = $f \n";

$g = $a - $b;
print "Subtraction \t\t\t: $a - $b = $g \n";

print "\n\n######### String operators - when values are numeric ######### \n";

$i = $a . $b;
print "Concatenation \t\t\t: $a . $b = $i \n";

$j = $a x $b;
print "Duplication \t\t\t: $a x $b = $j \n";

print "\n\n######### String operators - when values are strings ######### \n";

$str3 = $str1 . $str2 ;
print "Concatenation \t\t\t: $str1 . $str2 = $str3 \n";

$str4 = $str1 x 4 ;
print "Concatenation + multiplication \t: $str1 x 4 = $str4 \n";


print "\n\n\n\n";




Result:

################## BASIC OPERATIONS IN PERL ##################


#################### Arithmatic Operators ####################
Addition : 7 + 3 = 10
Multiplication : 7 * 3 = 21
Division : 7 / 3 = 2.33333333333333
Modulus : 7 % 3 = 1
Subtraction : 7 - 3 = 4


######### String operators - when values are numeric #########
Concatenation : 7 . 3 = 73
Duplication : 7 x 3 = 777


######### String operators - when values are strings #########
Concatenation : abc . def = abcdef
Concatenation + multiplication : abc x 4 = abcabcabcabc

No comments:

About Me

My photo
Unix geek with AWS, Cloud computing, Linux, Netapp, VMware, Scripting background! :)