From 3aafc7cd4e7c2a519b4651ac21e5d1e81c8f9511 Mon Sep 17 00:00:00 2001 From: KUEPPO Date: Sun, 16 Oct 2022 22:16:22 +0100 Subject: pwc-186, ch-2 in Perl --- challenge-186/kueppo-wesley/Perl/ch-2.pl | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-186/kueppo-wesley/Perl/ch-2.pl diff --git a/challenge-186/kueppo-wesley/Perl/ch-2.pl b/challenge-186/kueppo-wesley/Perl/ch-2.pl new file mode 100644 index 0000000000..ddddb1145e --- /dev/null +++ b/challenge-186/kueppo-wesley/Perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use Test::More; + +use Encode; +use Unicode::Normalize; + +sub makeover { + my $string = $_[ 0 ]; + + # Decompose unicode characters based on *Compatibility Equivalence* to obtain the + # ascii characters for which impurities have been added to build unicode $string. + $string = NFKD( $string ); + + # Change $string' encoding to ASCII + $string = encode( + 'ascii', + $string, + + # Strip the impurities + sub { '' } + ); + + return $string; +} + +# Testing.. +is( makeover( 'ÃÊÍÒÙ' ), 'AEIOU', "is 'AEIOU' its ascii equivalence?" ); +is( makeover( 'âÊíÒÙ' ), 'aEiOU', "is 'aEiOU' its ascii equivalence?" ); + +done_testing( 2 ); -- cgit