Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Hashes of arrays populated from a Text File

by sundialsvc4 (Abbot)
on Feb 26, 2014 at 15:38 UTC ( #1076268=note: print w/replies, xml ) Need Help??

in reply to Hashes of arrays populated from a Text File

Quite frankly, what I would do is to grab a copy of SQLite ... a public-domain SQL system that doesn’t use any kind of server ... and import all these files into a database, then use SQL queries to JOIN among the various tables to get the answers that you want.   You don’t have to write-a-program to import the data.

Also, if this happens to be a one-off task, consider the ubiquitous spreadsheet ... which will also certainly have the capability to obtain data from a database file and even to perform queries against it.   (Or do vlookup() and so-on.)

I’m just suggesting ... look at the target and all of the potential ways of hitting that target.   Sure, “writing a Perl program” is one way to do it.   Perl can do it effortlessly and other posts on this thread will show you exactly how.   But if what you have is a bunch of CSV files, and what you want to get is a result that can be described as joining data between them, then in all likelihood you do not need to “write a program” to do that.

  • Comment on Re: Hashes of arrays populated from a Text File

Replies are listed 'Best First'.
Re^2: Hashes of arrays populated from a Text File
by Laurent_R (Canon) on Feb 26, 2014 at 19:05 UTC
    You must be kidding, sundialsvc4. Using a database for such a simple task is just plain overkill. You can obtain the desired result with just a simple Perl one-liner:
    $ cat test_file.txt Name1 1234 Name2 9999 Name1 5514 Name3 5415 Name2 6419 $ perl -ne 'my ($key, $val) = split; $hash{$key} .= " $val"; END { pri +nt "$_ => $hash{$_} \n" for keys %hash;}' test_file.txt Name3 => 5415 Name1 => 1234 5514 Name2 => 9999 6419
    The result is there even before you start populating your database.
Re^2: Hashes of arrays populated from a Text File
by Raya4505 (Novice) on Feb 26, 2014 at 15:46 UTC

    That sounds awesome, and I have heard good things, unfortunately, my work won't give me approval to download it. So, I can't do that, but I have looked into it. Thank you for your suggestion.

      " work won't give me approval to download it...

      Do you mean the company you are with doesn't permit that you use some code you got from PM or elsewhere? But why?

      Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Re^2: Hashes of arrays populated from a Text File
by SimonPratt (Friar) on Feb 27, 2014 at 15:59 UTC

    Up-voted because of the hilarious nature of the overkill (and huge amount of work involved) in avoiding writing a one-line perl script

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1076268]
and the fire pops...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2018-01-19 22:11 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (223 votes). Check out past polls.