Perl abs Function



Description

This function 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 $_

Syntax

Following is the simple syntax for this function −

 abs VALUE abs 

Return Value

This function returns the absolute value of its argument.

Example

Following is the example code showing its basic usage −

 #!/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" ; 

When above code is executed, it produces the following result −

 Abs value of par1 is 10.25 Abs value of par2 is 20 Abs value of par3 is 0 
perl_function_references.htm
Advertisements