From the course: Perl 5 Essential Training

Unlock the full course today

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

Assignments

Assignments - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Assignments

- [Voiceover] An assignment is a statement that assigns a value to a variable. Here's a working copy of hello.pl from chapter three of the Exercise Files. I'm gonna come down here and create a simple assignment. I'll go ahead and run that, and you see the result is 47. The equal sign serves as a simple assignment operator. In this case, it assigns the value of a literal constant, the number 47, to the variable $x. We'll talk about scope later in this chapter, but for now, just know that the my keyword gives the variable local scope for this file. So, you can assign a literal constant like that, or you can assign a value from another variable. You can do something like this. And we'll go ahead and run that, and you see the result is the same 47. Or you can assign a value from any expression that returns a value. So, you could say something like this. And I'll go ahead and run that, and now the result is 157. Perl also supports compound assignment operators, which it's borrowed from the…

Contents