From the course: Perl 5 Essential Training
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Compound assignment operators - Perl Tutorial
From the course: Perl 5 Essential Training
Compound assignment operators
- [Voiceover] The compound assignment operators are a nice convenience feature that was borrowed from the C language. Here is a working copy of hello.pl from chapter eight of the exercise files. For example, if I come down here and I create a variable, and assign it a value, so I now I've got $x is equal to seven. And let's say that I want to add two to this. I could say, $x equals $x plus two, and say $x, and I'll get nine, and that's correct. Or I could use the compound assignment operator, I can take this assignment and the addition and put them in one operator, and say, plus equals, x plus equals two. And you notice I get exactly the same result. So this both adds and assigns in one operator. So that's why it's called the compound assignment operator. It has the side effect of only evaluating $x once, and there are circumstances where that may matter. In other words, if I were doing this in two steps like this, it actually evaluates $x twice. And if that were a class or something…
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.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
About Perl's operators2m 35s
-
(Locked)
Basic arithmetic operators5m 30s
-
(Locked)
Compound assignment operators2m 5s
-
(Locked)
Relational operators3m 27s
-
(Locked)
Logical operators6m 1s
-
(Locked)
File test operators3m 42s
-
(Locked)
The range operator2m 54s
-
(Locked)
The string concatenation operator1m 31s
-
(Locked)
Quote operators4m
-
(Locked)
-
-
-
-
-
-
-
-