AH 1106
AH 11989
AH 121
BH 120
BH 220
CH 330

I want result like

AH 1160 11989 121
BH 120 220
CH 330

Recommended Answers

All 2 Replies

Hi Everybody I am trying to get solution for above, with respect i will appeiciate any help

The code below should solve this quiet easily.

#!/usr/bin/perl
use warnings;
use strict;

my %lump_has;

while (<DATA>) {
    chomp;
    my ( $title, $value ) = split;
    push @{ $lump_has{$title} }, $value;
}

print join ' ', $_, @{ $lump_has{$_} }, $/ for keys %lump_has;

__DATA__
AH 1106
AH 11989
AH 121
BH 120
BH 220
CH 330

OUTPUT:

AH 1106 11989 121 
BH 120 220 
CH 330 

Please check perldoc perldsc for more information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.