in reply to simplify the code
I have to wonder though why @$sur is a hash with those keys instead of just an array ... can you explain where that data structure is coming from/what it's for?#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $sur = [ { 'one' => 'USA', 'two' => 'GOD', 'three' => '690 +557','four'=>'hello how are u',}, { 'one' => 'USA', 'two' => 'GOD', 'three' => '690 +557','four'=>'I am fine',}, { 'one' => 'UK', 'two' => 'GOD', 'three' => '6905 +58','four'=>'I am Okay',}, ]; my %h; foreach ( @$sur ){ if( exists $h{ $_->{three} } ){ $h{ $_->{three} } .= "####" . $_->{four}; }else{ $h{ $_->{three} } = join "<-->", @{$_}{ qw/one two four/ }; } } print Dumper \%h;
|
|---|