Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl would I use fc over uc?

Tags:

perl

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

Perl fc documentation

like image 823
Colton Love Avatar asked Dec 20 '22 03:12

Colton Love


1 Answers

fc is used for case-insensitive comparisons.

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

An example where this makes a difference:

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

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

Notice 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;
like image 104
ikegami Avatar answered Jan 05 '23 21:01

ikegami