From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Numeric functions

Numeric functions - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Numeric functions

- [Voiceover] Perl has a full complement of numeric and math functions. In this lesson, I'll show you some of the more common examples. Here's a working copy of math.pl from Chapter 13 of the exercise files. You notice if I run this, I get the result of 197, which is a + b. If I change this + to a -, you'll notice I get -103. Now, if I want the absolute value of that, which would be a positive number whether the argument is actually negative or positive, then I could use abs, which is the absolute value function. Notice, I don't need parentheses here because these are built in functions. I run that and I get 103, because that's the absolute value of -103. Perl also includes a number of math and trig functions. Here's just a couple. We have the arctan2, which is actually really convenient for calculating the value of pi. So, I can have 1,1 and multiply that by four, and I get the value of pi. Or I can take a square root. That's another common one. sqrt of $a, and that is 6.855, etc…

Contents