Next Tricks of the Wizards 57

Tied Hash Example

A hash with case-insensitive keys

        use Insensitive;
        tie %hash => Insensitive;
        $hash{SomeKey} = 'somevalue';
        $hash{'John MacDonald'} = 'Author';
        print $hash{somekey}, "\n";             # Prints `somevalue'
        print $hash{'John Macdonald'}, "\n";    # Prints `Author'
        $hash{SOMEKEY} = 57;
        print $hash{SomeKey}, "\n";             # Prints 57


Next Copyright © 2003 M. J. Dominus