Monks, what you see before you is a simple conglomerate of code designed to run under WinNT 4.0

The task is simple, it polls a directory full of text files, scans each one for a given search string. If the file has the string, the script then identifies any other files that "look-like" the given file.

("look-like" defines to "has the same seven character key in the filename")

The problem is this, the script operates on directories containing several hundred files, each ranging in size from a few hundred bytes, to a few dozen megabytes. It appears straightforward enough (to me) that each file is open, checked for the string, then closed, however it seems that the memory being used to hold this file is not being released, and I get huge build-ups of wasted memory.

Is there something in Windows or PERL that I'm forgetting?
Does the problem lie elsewhere than the file handling?

(note: all IP addresses and paths have been changed to anonymous values for posting purposes)

#!c:\perl -w use IO::File; use Shell; use strict; my @servers = qw(0.0.0.0 1.1.1.1 2.2.2.2); my $searchString = join(" ", (@ARGV)); foreach my $server (@servers) { my $path = '\\\SERVER\VOLUME\DIRECTORY\*'; my $dirPath = '\\\SERVER\VOLUME\DIRECTORY'; $path =~ s/SERVER/$server/g; $dirPath =~ s/SERVER/$server/g; my @dir = dir("$path"); foreach(@dir) { if(/^.*?\s+(\S+\.(\S{3}))$/) { unless($2 eq 'log' || $2 eq 'txt') { my $file = join('\\', ($dirPath, $1)); (my $numSet) = $1 =~ /^.([^.]+)\.\S{3}$/; undef $/; my $read = new IO::File; if($read->open("< $file")) { if(<$read> =~ /$searchString/g) { print "Found: $file\n"; foreach(@dir) { if(/^.*?\s+([A-Z]{1}$numSet\.\S{3})$/) { my $found = join('\\', ($dirPath, $1)); print "Found: $found\n"; } } } } } } } }

In reply to Where's the leak? by tekkie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.