Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl, how to lowercase all hash values?

I need to copy a (one-level) hash to a new one, with all values lowercased.

Do you know a smart method (just to avoid an ugly foreach... ;-)

like image 452
MarcoS Avatar asked Aug 10 '11 16:08

MarcoS


2 Answers

my %new = map { $_ => lc $old{$_} } keys %old;
like image 165
friedo Avatar answered Oct 27 '22 08:10

friedo


This is a one liner using map:

my %newHash = map { $_ => lc $existingHash{$_} } keys %existingHash;
like image 42
Kevin Brock Avatar answered Oct 27 '22 07:10

Kevin Brock