I have a hash with a certain set of data. I need to manipulate the hash values so that I can get result like below:
Expected Output:
key_1=Cell1
Val_1=C3#C4#C1#C2
Script:
#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;
use List::Util qw /uniq/;
my %hash = (
'Cell1' => {
'A' => [ 'C1','C2','C1','C2' ],
'B' => [ 'C3','C3','C4','C4' ]
}
);
print Dumper(\%hash);
my $i = 0;
foreach my $key (keys %hash) {
++$i;
print "key_$i=$key\n";
foreach my $refs (keys %{ $hash{$key} }) {
print "Val_$i=", join('#', uniq @{$hash{$key}{$refs}})."\n";
}
}
Current Output:
key_1=Cell1
Val_1=C3#C4
Val_1=C1#C2
How can I get the expected output here?