Would Perl use fc over uc?

When will you ever need to use fc(), when uc()will it ever fail?

Perl fc documentation

+4
source share
1 answer

fc used for case insensitivity.

uc($a) cmp uc($b)    # XXX
lc($a) cmp lc($b)    # XXX
fc($a) cmp fc($b)    # ok

An example where it matters:

   lc uc fc
-- -- -- --
ss ss SS ss
SS ss SS ss
ß  ß  SS ss
  ß  ẞ  ss

Note that fc ("ß") eq fc ("ẞ"), but uc ("ß") ne uc ("ẞ").

Note that fc ("ß") eq fc ("ss"), but lc ("ß") ne lc ("ss").


The table was generated using

use strict;
use warnings;
use feature qw( fc );

use open ':std', ':encoding(UTF-8)';

my $ss = "\N{LATIN SMALL LETTER SHARP S}";
my $SS = "\N{LATIN CAPITAL LETTER SHARP S}";

printf("   lc uc fc\n");
printf("-- -- -- --\n");
printf("%-2s %-2s %-2s %-2s\n", $_, lc($_), uc($_), fc($_))
   for 'ss', 'SS', $ss, $SS;
+11
source

All Articles