http://www.perlmonks.org?node_id=11154176

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear Monks!
I have a file in the form of:
nick 5 nick 10 george 2 peter 3 george 14 nick 20
and I want to output:
george:2,14 nick:5~~10~~20 peter:3

I had an old script that used to work:
use strict; use warnings; my %res; while (<>) { chomp; my ( $name, $rest ) = split /\t/; push @{ $res{$name} }, $rest; } for $a( sort keys %res ) { print "$a:". join( "~~", @{ $res{$a} } ); print "\n"; }
Now it produces weird results, can you please help me fix it? Perhaps I introduced a bug at some point and now I can't get it to work.
Current output (weird):
~~14ge:2 ~~20:5 peter:3