Re: Merge multiple rows and remove duplicates --based on the first value



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
.



Relevant Pages

  • Re: Vote to Save Your Job -- Vote for Kerry
    ... BONG BONG BONG, JG ... Main Entry: de·ter·mine ... Middle English, from Middle French determiner, from Latin ... struck /'str&k/; struck also strick·en ...
    (comp.programming)
  • Re: GH: Spoiler: A.J.s Killer is..........
    ... > Susan Barnett wrote: ... What motive would compel Dr. Thomas to kill him? ... >> once again being tormented and victimized by the evil police, lawyers and, ... Did you hear that speech Sonny made to Reese on Thursday's show when she was ...
    (rec.arts.tv.soaps.abc)
  • Re: Hide rows to create summary
    ... You can do it with a single statement, but you must show a colon delimited start and end row for each entry in the list... ... To ensure that the full data set is always present it struck me that I ...
    (microsoft.public.excel.programming)
  • Re: Pharmas editing wikipedia entries
    ... Susan wrote: ... it is Wikapedia - home of fraudulent and idealogical thuds distributing misinformation ... Anyone expecting a WikiWaki entry to mean anything deserves what they get ...
    (alt.support.diabetes)
  • Re: [OT][Spoilers] Muggle Musings on Book 6
    ... I was struck by some thoughts ... ... > You don't have to read the Harry Potter books if they upset you so much. ... > Susan Silberstein ... I'm pretty sure that Clyde isn't saying that the Harry Potter series ...
    (talk.origins)