[ Please do not top-post.  TIA ]

tianjun xu wrote:
This works.

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

my %hash=();
while(<>){
        chomp(my $line=$_);
        my($col1, $col2)=split(/\s+/, $line);

Or just:

while ( <> ) {
        my ( $col1, $col2 ) = split;


        push(@{ $hash{$col1} }, $col2);
}

for my $key (sort keys %hash){
         print "$key";
         for (@{ $hash{$key} }){
                print " $_";
        }
        print "\n";

Or just:

for my $key ( sort keys %hash ) {
    print "$key @{$hash{$key}}\n";


}



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to