Probably an easy one ...
I have a piece of code that hashes a directory structure using
the use File::Recurse package. It looks like ...
%files = Recurse([$drive], {match => '\.'});
... and then I can shuffle through it like so ...
foreach $dir (sort keys %files)
{
foreach $file (@{ $files{$dir} })
{
# Do work
}
}
The trouble is that there are
literally millions
of files in the hash and as you can imagine, that's taking
up a lot of memory ... don't ask.
The process is able to hash the entire structure
without any trouble but somewhere in loop of the program
I get "Out Of Memory" errors. Undoubtedly
this is the result of the aforementioned hash. I don't need
to keep any element of that hash around after I have used it, so my question is, "How do I delete the entries from the hash one-by-one? In other words, how do I deallocate the memory of an entry in the hash individually or is it even possible? Obviously, I hope this would allow me to avoid the memory errors, thought I fear that might happen at the expense of a great deal of memory management overhead.
Between a rock and a hard place,
Pearte
PS - If anyone has a better strategy for dealing with as many files, I'd like to hear it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.