in reply to changing the hash key as upper case.
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Scalar::Util qw(reftype); sub Hash_Key_Cap { my $entry=shift; # reftype() my return undef, don't warn about that: no warnings 'uninitialized'; if (reftype($entry) eq 'HASH') { my %h = map { uc $_ => Hash_Key_Cap($entry->{$_}) } keys %$ent +ry; return \%h; } elsif (reftype($entry) eq 'ARRAY') { return [ map Hash_Key_Cap($_), @$entry ]; } else { return $entry; } } my %hash=( 'a'=>'Wow', 'b'=>['GOOD', 'BAD'], 'c'=>[ { one=>'perl', two=>'monks', five=>{a=>'b',c=>{ c=>'d' } }, three=>'Test', four=>'Best' }, 2 ], 'd'=> { five=>5, size=>6 }, ); print Dumper(Hash_Key_Cap(\%hash));
Note that proper indention is essential for the readability of the code.
|
|---|