Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-01-23 04:35 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (238 votes). Check out past polls.