Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why is my code producing weird output?

by GrandFather (Saint)
on Aug 30, 2023 at 23:30 UTC ( [id://11154180]=note: print w/replies, xml ) Need Help??


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.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-06-17 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.