From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Basic arithmetic operators - Perl Tutorial
From the course: Perl 5 Essential Training
Basic arithmetic operators
- [Voiceover] The basic arithmetic operators include addition, subtraction, multiplication, and division, and also for our purposes, I'm including the modulo operator as it returns the remainder of integer division. And I'm gonna start by, my cursor in the right place, and we'll just declare a few variables. my $x, give that a value of 47. And $y will be four. And now I can do something like say $x plus $y, and when I run that, we get 51, which is the correct answer. And if I say x minus y, we get 43. That's what we expect. Or x times y, with the asterisk. Get 188. And x divided by y, we get 11.75. Now you notice there's a fractional part here, the 0.75, which will be three-quarters. Or after dividing 47 by 4, there would be a remainder of three, so if I say modulo, then I have that three. That's the percent sign for the modulus operator. Now if I want to do actual integer division, because remember here we're getting, with the divide operator, we're getting the fractional part. If I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.