in reply to If two variables match

There are many ways you could move forward from here:

  1. One way is to convert both values to a unified representation, for example all-upper-case or all-lower-case, and then compare the two with simple string equality:
    if (uc $vord eq uc $nick) { ... }
  2. Another way is to compile your $nick into a safe regular expression and check against that:
    if ($vord =~ /^\Q$nick\E$/i) { ... }
    The \Q .. \E escapes turn of the interpretation of all regular-expression metacharacters in-between them.

Replies are listed 'Best First'.
Re^2: If two variables match
by Tanktalus (Canon) on Nov 25, 2005 at 04:42 UTC

    Side note on option 1. English may let you get away with uc'ing to do a comparison. Certain other languages do not. It's just a good I18N habit to get into to always use lower-case to compare. I've never really fully understood this advice from our I18N experts at work, but I take their word for it. Even if that makes me a bit of a cargo-culter. I'm not ashamed to admit it - I'm a unilingual person, so to keep from ticking off our Nordic customers, I'm more than happy to follow this advice. ;-)

    Also, side note on option 2 - I think that option 1 is likely to be significantly faster. Benchmark to be sure.

      If you want to give your language experts a counter example, in German, the "sharp-S" / "eszet" letter "ß", compounded of "s" and "z", has no uppercase equivalent and is always written as "SS" when uppercased. For example straße ("street") becomes STRASSE. If you want to match case-insensitively here, you either have to normalize all ß to "ss" before comparing or you can "normalize" by converting to upper case.

      But I admit that this is some corner case which is unlikely to affect non-Germans :-)