Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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:

/^(?i:-?content[_-]length)$/

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

$hash{'^(?i:-?content[_-]length)$'}

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


Dave


Comment on Re: On creating hash whose keys aren't case-sensitive
Select or Download Code
Re^2: On creating hash whose keys aren't case-sensitive
by anazawa (Beadle) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-07-28 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (209 votes), past polls