In French (and other european languages) we often need to make accent-insensitive comparisons. For example, users of a web site will type andromede in a search box and expect that to match andromède.

This code creates accent-insensitive lc and uc functions. They work like the builtins but get rid of any accents.

Usage:

print iso_8859_1_lc("andromède"); # prints "andromede"; print iso_8859_1_uc("andromède"); # prints "ANDROMEDE";
use strict; my %iso_8859_1_accents = ( a => [ qw(à á â ã ä å À Á Â Ã Ä Å) ], c => [ qw(ç Ç) ], e => [ qw(è é ê ë È É Ê Ë) ], i => [ qw(ì í î ï Ì Í Î Ï) ], n => [ qw(ñ Ñ) ], o => [ qw(ò ó ô õ ö ø Ò Ó Ô Õ Ö Ø) ], u => [ qw(ù ú û ü Ù Ú Û Ü) ], y => [ qw(ý Ý) ], ); # build translation strings my (%in, %out); for my $letter ('a'..'z') { my $uletter = CORE::uc $letter; # translate non-accented letters $in{uc} .= $letter; $out{lc} .= $letter; $in{lc} .= $uletter; $out{uc} .= $uletter; if (my $ra_accented = $iso_8859_1_accents{$letter}) { my $in = join '', @$ra_accented; $in{lc} .= $in; $in{uc} .= $in; $out{lc} .= $letter x @$ra_accented; $out{uc} .= $uletter x @$ra_accented; } } # build translation subroutines for my $type (qw(lc uc)) { my $sub = qq! sub iso_8859_1_$type { (my \$s = shift) =~ tr/$in{$type}/$out{$type}/; \$s } !; eval $sub; }

In reply to Accent-insensitive case conversion by echo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.