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);
In reply to Re: write to Disk instead of RAM without using modules
by Laurent_R
in thread write to Disk instead of RAM without using modules
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |