Oh monks most exalted and wise, a humble novice seeks to benefit from your vast knowledge of all things Perl.
I have a text file (UTF8-encoded) containing words, one per line, and I'm interested in finding out, for each word, how many characters are in it that do not appear in the English alphabet. So I whipped up a script to find out:
#!/usr/bin/perl use open IO => ':utf8'; while(<>) { chomp; ($nonenglish = $_) =~ s/[A-Za-z]//g; print length($nonenglish), " $nonenglish\n"; }
Alas, it isn't working; length appears to be counting bytes rather than characters! To wit:
$ perl nonenglish.pl æ 2 æ ꝥ 3 ꝥ 𪛖 4 𪛖 ^D $
I only occasionally use Perl, and I have no idea what I'm doing wrong. Enlighten me, kind monks, I beseech you!
My Perl is 5.14.2, BTW (and I cannot easily upgrade).
In reply to length() miscounting UTF8 characters? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |