Is there a way to create a UTF-8 alphabet array using the Perl ‘..’ operator?
For example, this one won’t work:
$ cat t.pl
#!/usr/bin/perl
use Data::Dumper;
use encoding 'utf8';
print Dumper('А'..'Я'); # not working!
print Dumper('А','Б','В'); # ...works fine! but needs to be filling letter by letter
$ perl t.pl
$VAR1 = "\x{410}";
$VAR1 = "\x{410}";
$VAR2 = "\x{411}";
$VAR3 = "\x{412}";
$ echo $LANG
en_US.UTF-8
Any advice?
This is mentioned – briefly – in the range operator docs.
You need to use the ord and chr functions:
Output:
The result you see arises because the initial value of the range isn’t part of a ‘magical’ sequence (a non-empty string matching
/^[a-zA-Z]*[0-9]*\z/), so the operator just returns that initial value.