Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by davido (Cardinal)
on Feb 18, 2012 at 09:54 UTC ( [id://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

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found