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 variables - Perl Tutorial
From the course: Perl 5 Essential Training
Numeric variables
- [Voiceover] In Perl, a numeric value is one that can be represented as a number, and can be used in mathematical expressions. Here's a working copy of hello.pl from chapter four of the exercise files. I'll just go ahead and run it. You see it says, hello world, and I'm gonna come in here, and I'm going to declare a scalar variable. My $n = 42, so by the fact that I've assigned a number to it, we know that this can be used in a numeric context, and if I say n is $n, and I'll go ahead and run this, you see it says n is 42. Now, If I come up here and I say, $n = $n x 2, then I save and run, and you see it says n is 84, or if I say $n = $n + 100, and save and run. You see it says n is 142. On the other hand, if I say, $n = $n, dot, which is the string concatenation symbol, and say, space foo, like that in single quotes. Then when I save and run, you see it says, n is 42 foo, and if I go and put some brackets around this, you can see where the variable starts and ends in the string Save…
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.