Home / Perl / Archive by category 'Perl Functions'

Perl Functions

PERL abs Function

Syntax

abs VALUE
abs

Definition and Usage

Returns the absolute value of its argument. If pure interger value is passed then it will return it as it is but if a string is passed then it will return zero. If VALUE is omitted then it uses $_

Return Value
Returns the absolute value of its argument.

Example

#!/usr/bin/perl
 
$par1 = 10.25;
$par2 = 20;
$par3 = "ABC";
 
$abs1 = abs($par1);
$abs2 = abs($par2);
$abs3 = abs($par3);
 
print "Abs value of par1 is $abs1\n" ;
print "Abs value of par2 is $abs2\n" ;
print "Abs value of par3 is $abs3\n" ;

This will produce following result

Abs value of par1 is 10.25
Abs value of par2 is 20
Abs value of par3 is 0