in reply to Regexes for Case Change

If you are looking to drop the case on all of the characters in your string, you could easily perform this with the transliteration operator - For example:

$string =~ tr [A-Z] [a-z];

 

Replies are listed 'Best First'.
Re: Re: Regexes for Case Change
by Molt (Chaplain) on May 08, 2002 at 12:08 UTC

    Ithink it's generally better to do this with the lc operator rather than tr since lc handles localisation character sets (Umlauts and so forth) and unicode properly.

    Not that I think it matters in this case, but it's probably one of those things where when you get into one style you may as well get into the one which won't make you trip when you expand what you're working with.


      I think it's generally better to do this with the lc operator rather than tr since lc handles localisation character sets

      Only if "use locale" is in effect. Otherwise the following is unlikely to do anything:     print uc 'ü';

      This assertion also depends on what the "general" case is considered to be. The general case is probably a single character set so a transliteration, as shown by rob_au, is probably sufficient.

      --
      John.

      While the perlfunc:tr operator may not handle localisation character sets, it does have the advantage over substitution of speed as it doesn't perform interpolation or use the regex engine. As such, the choice between functions really comes down to the data being manipulated and whether character and locale classes will come into effect.

      The transliteration solution was provided more so for proof of TMTOWTDI, YMMV.