Skip to content

Instantly share code, notes, and snippets.

@hgiddens
Created September 23, 2014 02:48
Show Gist options
  • Select an option

  • Save hgiddens/2011d316ed661361f26f to your computer and use it in GitHub Desktop.

Select an option

Save hgiddens/2011d316ed661361f26f to your computer and use it in GitHub Desktop.
Macrons and Perl
#!/usr/bin/env perl
# First up, this is the bible:
# https://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default
# Also good
# man perluniintro
# man perlunitut
# man perlunicode
# Tested via `PERL_UNICODE=S perl test.pl < macron.txt` where macron.txt just contained
# the $input string in NFC UTF-8.
use local::lib; # I need this for Modern::Perl
use Modern::Perl;
use v5.14;
use utf8;
my $input = "Tū Māori Mai! That’s us!\n";
# Have PERL_UNICODE=S (at least) in the environment for this process or
# uncomment the following lines:
# binmode(STDIN, ":utf8");
# binmode(STDOUT, ":utf8");
# With the above, these lines both correctly output capital letters with
# macrons (with the characters with macrons in their composed forms).
print uc($input);
print length($input) . "\n"; # 25
while (<>) {
print uc;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment