To easily iterate over a range of characters in Perl, we can use the range operator to define an array of chars.
Then, we can iterate over each element with a for-each loop.
This can be useful when iterating over objects named alphabetically instead of numerically, for example.
The code is below.
use strict; my @chars = ('a'..'z'); foreach my $c (@chars) { print("Current char: $c \n"); }
Truncated output:
Current char: a Current char: b Current char: c Current char: d Current char: e Current char: f ... Current char: z