in reply to print identical keys once along with their values
$ perl -wMstrict -MData::Dumper -e 'my $pair = qr{ (\d+) \s+ ([[:alpha +:]]+) }xms; > my $record = "1 A 1 B 2 G 2 H 2 V"; > my %hash; > while ($record =~ m{ \G \s* $pair }xmsg) { > $hash{$1} .= "$2;"; > } > print Dumper \%hash; > ' $VAR1 = { '1' => 'A;B;', '2' => 'G;H;V;' };
|
|---|