Ken Foskey wrote:
On Wed, 2007-02-14 at 12:37 +0100, Arantxa Otegi wrote:
I have memory problems programming with perl: "out of memory!"

I have to process a lot of xml files which are in different directories (more than 20000 files in 110 directories). The files are quite small (almost all of them are smaller than 100KB).

opendir(DIR,$sarrera_dir)|| die "ezin da ireki DIR: $sarrera_dir";
@dirs = readdir(DIR);
closedir(DIR);

foreach $dir (@dirs){

opendir(DIR,$sarrera_dir)|| die "ezin da ireki DIR: $sarrera_dir";
while( $dir = readdir(DIR) ){
}
closedir(DIR);

It should be obvious why this is taking less memory.

Well it is obvious, but I doubt if that is the source of the problem. At a rough
guess each element of the array of directory names will take up 40 bytes or so.
Since there are 110 of these, pulling them all into memory at once will
sacrifice around 4KB of memory - hardly a big problem. More interesting is the
20,000 files but, even if the names of these were all in memory at the same
time, their total size would total under a megabyte. So the problem doesn't lie
here.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to