1. Perl
  2. Operators
  3. here

Range operator - m .. n

Perl has a range operator that allows you to specify a range of numbers.

# Range operator
3 .. 6

The result is list of (3, 4, 5, 6).

Normally, it is assigned to array or used in for statement.

my @nums = (3 .. 6);

for my $num (3 .. 6) {
  ...
}

You can also specify a range of alphanumeric characters.

'a' ..' z'

Example program

This is an example program of the range operator.

use strict;
use warnings;

my @nums = (3 .. 6);

for my $num (@nums) {
  print "$num\n";
}

The output result is as follows.

3
Four
Five
6

Related Informatrion