in reply to Why is my code producing weird output?
Maybe your input data is not what you think it is? Instead of piping the data in try using an external file or baking the data into a test script:
use strict; use warnings; my %res; while (<DATA>) { chomp; my ( $name, $rest ) = split /\t/; push @{ $res{$name} }, $rest; } for $a( sort keys %res ) { print "$a:". join( "~~", @{ $res{$a} } ); print "\n"; } __DATA__ nick 5 nick 10 george 2 peter 3 george 14 nick 20
Prints:
george:2~~14 nick:5~~10~~20 peter:3
Note that that result is not what you say you want, but your code suggests the comma you show as a separator for george is a typo anyway.
|
|---|