Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: creating and managing many hashes

by LanX (Cardinal)
on Feb 18, 2018 at 13:20 UTC ( #1209433=note: print w/replies, xml ) Need Help??


in reply to creating and managing many hashes

> I have currently done this using arrays over the 2 million pairs that arise from 2,000 products and it ran for 4 days before

I think your speed problems result from linear searches.

You may want to organise your data in a nested structure.

See perldsc And perlref

Like (draft)

$h_record = { date => '2018-01-01', product => 'apple', price => 200, quantity => 50000, }; $product{apple}{'2018-01-01'} = $h_record; $date{'2018-01-01'}{apple} = $h_record;
  • Like this you can easily lookup products and dates and pass records to subroutines.
  • Another hint is to cache and not repeat already done calculations.
  • Last but not least keep an eye on memory consumption, as soon as the system needs to swap heavily, you'll be lost in a black hole. (Only processing chunks may help here)

Please note (like others mentioned) that this approach can't compete with an SQL DB in terms of efficiency.

Those hashes need lots a memory where a SQL is managing an index on columns of the same table. (Think of all the hashes you'd need to easily look up year, month and day separately)

Also reading files to build the data structure will cause you overhead where SQL is persistent.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-06-16 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (80 votes). Check out past polls.

    Notices?