Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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 (Abbot) 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.

      "...my 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1076268]
help
Chatterbox?
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already
[perldigious]: Snowshoeing time stevieb? I need to buy a pair so I can walk my German Shepherd properly through the country.
[stevieb]: yeah, I snowshoe a fair amount in the mountains. I also use spikes similar to these very often as well
[perldigious]: Discipulus: alternate link
[stevieb]: LOL you can easily replace "Helsinki" with "Alberta"
[perldigious]: I used to live at the top of a very steep hill stevieb, I can relate to the video. Literally used to have to build up momentum and try to force my vehicle to make it up the hill to park in my driveway properly... didn't always make it.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-12-06 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.