Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Hashes of arrays populated from a Text File

by toolic (Chancellor)
on Feb 26, 2014 at 14:57 UTC ( #1076257=note: print w/ replies, xml ) Need Help??


in reply to Hashes of arrays populated from a Text File

Use a hash-of-arrays (perldsc)

use warnings; use strict; use Data::Dumper; my %Diag; while (<DATA>) { my ($name, $val) = split; push @{ $Diag{$name} }, $val; } print Dumper(\%Diag); __DATA__ Name1 1234 Name2 9999 Name1 5514 Name3 5415 Name2 6419


Comment on Re: Hashes of arrays populated from a Text File
Download Code
Re^2: Hashes of arrays populated from a Text File
by Raya4505 (Novice) on Feb 26, 2014 at 15:36 UTC

    That is what my code essentially already does. I am needing the script to combine the names that are the same and compile the date in one hash. I want the values to be able to repeat, but not the names. Sorry if that wasn't clear.

    The data should look like:

    Name1 => value1 value2 value3 Name2 => value4 value5 value5 Name3 => value6 value7 value8

      Have you run toolic's code? It does exactly what you desire.

        Yes, I did and I guess I must be missing something. It is printing out symbols. I'll toy with it some more, but the data output he showed isn't exactly what I'm looking for. Thank you though
        Good grief. I am so silly. I had a typo. It works perfectly. You rock, I stink! Thanks so much!!!
      Unless I've mis-interpreted it, having done the hard work as posited by toolic, the problem is now down to the printed representation - maybe this, or something not unlike it, is more along the lines of what you're seeking...
      use warnings; use strict; use Data::Dumper; my %Diag; while (<DATA>) { my ($name, $val) = split; push @{ $Diag{$name} }, $val; } print "$_ => " . join(' ', @{$Diag{$_}}) . "\n" for keys %Diag; __DATA__ Name1 1234 Name2 9999 Name1 5514 Name3 5415 Name2 6419

      A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-23 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls