Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: On creating hash whose keys aren't case-sensitive

by davido (Archbishop)
on Feb 18, 2012 at 09:54 UTC ( #954730=note: print w/replies, xml ) Need Help??

in reply to On creating hash whose keys aren't case-sensitive

I haven't personally used the module, but it might be an opportunity to try out Tie::Hash::Regex. Your content-length key could match against a regex like this, for example:


From looking over the synopsis, the lookup would be as follows:


Realistically though, it's probably better to leave hash behavior alone, and just normalize your input before trying to do key lookups.


Replies are listed 'Best First'.
Re^2: On creating hash whose keys aren't case-sensitive
by anazawa (Scribe) on Feb 18, 2012 at 16:29 UTC
    Thanks for your suggestion. Tie::Hash::Regex interests me. I confirmed your regex passed the following test:
    # tie_hash_regex.t use strict; use Tie::Hash::Regex; use Test::Simple tests => 8; my @keys = qw( content-length content_length -content-length -content_length Content-Length Content_Length -Content-Length -Content_Length ); for my $key ( @keys ) { my %hash; tie %hash, 'Tie::Hash::Regex'; $hash{ $key } = 1234; ok $hash{'^(?i:-?content[_-]length)$'} == 1234; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954730]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2016-10-25 01:00 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.