And just for the fun of it: your _lc rewritten into one regex:
This sub returns undef (indicating an error) if you give it a string with more than one internal dash or underscore.use Modern::Perl; sub _lc { my $key = shift; my $success = $key =~ s/^-?([^-_]*)[-_]?([^-_]*)$/$2?lc"$1_$2":lc$ +1/e; return $key if $success; } print _lc($_) while (<DATA>); __DATA__ content-length content_length -content-length -content_length Content-Length Content_Length -Content-Length -Content_Length changed Changed -changed -Changed Too-many_dashes-Or-underscores
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: On creating hash whose keys aren't case-sensitive
by CountZero
in thread On creating hash whose keys aren't case-sensitive
by anazawa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |