in reply to Comparing/Completing Hashes
Sorry for all the backslashed double-quotes:
>perl -wMstrict -le "my @data = ( { \"name\" => \"joe\", \"age\" => 21, \"weight\" => 150, \"height\" => \"\", \"sex\" => \"\", }, { \"name\" => \"joe\", \"age\" => \"\", \"weight\" => \"\", \"height\" => \"6'0\", \"sex\" => \"\", }, { \"name\" => \"joe\", \"age\" => \"21\", \"weight\" => \"\", \"height\" => \"\", \"sex\" => \"male\", }, ); my %hash = map { my $hr = $_; map { $_, $hr->{$_} } grep $hr->{$_} ne '', keys %$hr } @data ; use Data::Dumper; print Dumper \%hash; " $VAR1 = { 'name' => 'joe', 'weight' => 150, 'sex' => 'male', 'height' => '6\'0', 'age' => '21' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing/Completing Hashes
by jjw92 (Novice) on Aug 13, 2010 at 23:32 UTC | |
by planetscape (Chancellor) on Aug 14, 2010 at 06:13 UTC | |
by AnomalousMonk (Archbishop) on Aug 13, 2010 at 23:59 UTC |