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.

The range operator

The range operator - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

The range operator

- [Voiceover] The Perl range operator returns a list of values according to a given range. Here's a working copy of range.pl from Chapter 8 of the exercise files. The range operator, you'll see it down here in line 7. It's those two dots in the the foreach clause right there. in the foreach clause right there. The range operator takes two values. The left-hand value is the lower bound of the range and the right-hand value is the upper bound of the range. The range operator returns a list including all values from the lower to the upper, including the values of the two operands. When I run this, you'll notice that I get a list of these values starting with 1 and ending with 10. If I want to, I can create a couple of variables here: my $lower, and I'm going to give that a letter a and my $upper, and I'm going to give that a letter zed or z and I'm just going to change these to $lower and $upper. The range can be numbers, it can be strings, it can be individual letters, and it'll do its…

Contents