Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 browsing the Monastery: (5)
As of 2014-09-16 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (158 votes), past polls