Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: string related query

by Eliya (Vicar)
on Nov 22, 2011 at 15:47 UTC ( #939478=note: print w/replies, xml ) Need Help??

in reply to string related query

There are many ways to do this.  Here's one suggestion:

my %out; while (<DATA>) { chomp; my ($id, $name) = split ' ', $_, 2; # split line into two parts ($id) = $id =~ /^([^.]+)/; # extract "name1", "name2" as + $id $out{$id} .= " $name"; # assemble stuff by $id (in a + hash) } for my $id (sort keys %out) { print $id, $out{$id}, "\n"; } __DATA__ name1 TOM RAT name1.1 AND name1.1.1 JERRY name2 BAT MAN name2.1 CAN name2.1.1 FLY name2.1.2 ANYWHERE

(feel free to ask if you need more detailed explanations)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939478]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2016-10-28 21:27 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.