in reply to write to Disk instead of RAM without using modules
Suppose you have one file containing the following words (one word per line): "two, four, six, seven", a second file containing "one, three, four, seven, eight", and a third file containing "two, four, seven, nine".
Read the first file and store the words in a hash with a value 1. You get a hash looking like this:
Read the second file line by line, and, for each line, check if the line is in the hash. If it isn't there, just discard the line: it wasn't in the first file, it cannot be in all files. If it is in the hash, just increment the counter for it. Your end up with somehing like this:( two => 1, four => 1, six => 1, seven => 1);
Repeat the same process with the third file, and you get:( two => 1, four => 2, six => 1, seven => 2);
Notice that your hash is not growing, even though you've read three files. Only one file has ever been loaded into memory. Now you know that the records common to all files are those whose value is 3, you can just print them or do whatever you want with them.( two => 1, four => 3, six => 1, seven => 3);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: write to Disk instead of RAM without using modules
by Laurent_R (Canon) on Oct 25, 2016 at 16:25 UTC | |
by Anonymous Monk on Oct 26, 2016 at 05:06 UTC | |
by Laurent_R (Canon) on Oct 26, 2016 at 06:20 UTC | |
by Anonymous Monk on Oct 26, 2016 at 09:15 UTC | |
by Anonymous Monk on Oct 26, 2016 at 05:41 UTC | |
by Anonymous Monk on Oct 26, 2016 at 11:53 UTC | |
by Corion (Patriarch) on Oct 26, 2016 at 11:58 UTC | |
by haukex (Archbishop) on Oct 26, 2016 at 12:01 UTC | |
by Laurent_R (Canon) on Oct 26, 2016 at 22:31 UTC |