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

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)


Comment on Re: string related query
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (17)
As of 2015-06-03 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?















    Results (138 votes), past polls