Andrej Kastrin schreef:

> id001  text1
> id001  text2
> id001  text3
> id002  text23
> id002  text555
> id003  text666
> 
> and want something like:
> 
> id001 text1 text2 text3
> id002 text23 text 555
> id003 text666

$ perl -MData::Dumper -aF -ne \
  'push @{$HoA{$F[0]}}, $F[1];} {END{print Dumper %HoA}' \
  infile

or:


  #!/usr/bin/perl

  use strict;
  use warnings;

  my %HoA;

  while (<>) {

      my ($group, $member) = split;

      push @{$HoA{$group}}, $member;
  }


  {   local ($,, $\) = ("\t", "\n");

      for my $group (keys %HoA) {

          print "$group:", @{$HoA{$group}};
      }
  }


See `perldoc perldsc`, look for "HASHES OF ARRAYS".


-- 
Grtz, Ruud

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to