in reply to Matching case insensitively in Hashes

  1. use only lower case keys when you set up your hash
  2. before you use the key to retrieve a value, lowercase it, like this:  $hash{lc $input}

Also, your syntax in the if statement isn't quite right. You are assigning a value to $match rather than comparing match to the hash value. To compare the values use:

See perlop for details.

Best, beth

Update: added clarifications on "use ... keys"

Replies are listed 'Best First'.
Re^2: Matching case insensitively in Hashes
by almut (Canon) on Feb 11, 2009 at 09:48 UTC
    Also, your syntax in the if statement isn't quite right. ...

    I believe the idea was simply to test if there exists an entry for $input in the hash and the associated value evaluates to 'true', i.e.

    if ($hash{$input}) { ... }

    The additional assignment to $match is presumably just for easier subsequent access to the value (such as in the print statement)...  (Only the OP will be able to tell, however, what the real intention was :)