Re: Merge multiple rows and remove duplicates --based on the first value
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Jan 2006 10:44:51 -0800
In article <1138322821.141463.215580@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Xicheng <xicheng@xxxxxxxxx> wrote:
> Susan wrote:
> > There must be a simple solution, but I am struck with this.
> > How do I merge these into one based on the first column?
> > Based the name "Thomas" I would like to merge the rest of the 3 columns
> > and get
> use hash..
> ==================
> #!/usr/bin/perl -w
> use strict;
> use Data::Dumper;
> my %h=();
> while(<DATA>) {
> chomp;
> my @tmp=split' ',$_,2;
> $h{$tmp[0]} .= "$tmp[1] ";
> }
> print Dumper \%h;
> __DATA__
> Thomas Jacob Emily Madison
> Corner Joshua Emma Isabella
> Thomas Ethan Emily Samantha
> Williams Mathew John Lina
> Corner Christopher Emma Daniel
> Corner Joshua Matthew Hannah
The OP doesn't want duplicate entries in the output. Your program does
not fulfill that requirement. For example, it includes 'Emily' twice in
the entry for 'Thomas'.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.
- Follow-Ups:
- References:
- Prev by Date: Re: string manipulation
- Next by Date: Re: IO::Select->can_read returns immediately
- Previous by thread: Re: Merge multiple rows and remove duplicates --based on the first value
- Next by thread: Re: Merge multiple rows and remove duplicates --based on the first value
- Index(es):
Relevant Pages
|