Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Hashes of arrays populated from a Text File

by Tux (Monsignor)
on Feb 26, 2014 at 17:52 UTC ( #1076297=note: print w/ replies, xml ) Need Help??


in reply to Hashes of arrays populated from a Text File

Just for the alternative, splitting on TAB triggers me to mention Text::CSV_XS (using toolic's hash approach):

use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ sep_char => "\t", auto_diag => 1 }); my %Diag; while (my $row = $csv->getline (*DATA)) { push @{$Diag{$row->[0]}}, $row->[1]; } $csv->eol ("\n"); $csv->sep_char (","); $csv->print (*STDOUT, [ $_, @{$Diag{$_}} ]) for sort keys %Diag; __DATA__ Name1 1234 Name2 9999 Name1 5514 Name3 5415 Name2 6419

-->

Name1,1234,5514 Name2,9999,6419 Name3,5415

Enjoy, Have FUN! H.Merijn


Comment on Re: Hashes of arrays populated from a Text File
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-10-21 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls