Back then you had to use local with a typeglob:

But either way, recursing directories while keeping their handles open will eventually run out of file handles.

Demo, repeatedly opening the current directory just to use up all available handles:

#!/usr/bin/perl use strict; use warnings; sub openHandle { opendir my $dir,'.' or die "Could not opendir: $!"; return $dir; } my @a; while (1) { push @a,openHandle(); print "Handles in use: ",0+@a,"\n"; }

Running on Linux 64 bit, using perl 5.22.2:

// previous lines removed Handles in use: 1015 Handles in use: 1016 Handles in use: 1017 Handles in use: 1018 Handles in use: 1019 Handles in use: 1020 Handles in use: 1021 Could not opendir: Too many open files at handles.pl line 8.

Add three handles for STDIN, STDOUT, STDERR, and you get a total of 1024 handles. Note that no other files, directories, or network connections are currently open.

Running on Windows 7 64 bit, Strawberry Perl 5.14.2 64 bit:

// previous lines removed Handles in use: 27781 Handles in use: 27782 Handles in use: 27783 Handles in use: 27784 Handles in use: 27785 Terminating on signal SIGINT(2) H:\tmp>

It takes several seconds to clean up the mess after pressing Ctrl-C.

According to MS Technet, Windows can open about 16.7 million handles.

MSDOS, in its default configuration, had a file handle limit of just 8, including STDIN, STDOUT, STDERR, plus two extra default handles for a communication port and a printer port. This left software with just three handles. Using the FILES directive in config.sys, you could increase that to 255 handles, a typical value was 20 or 30.

If you want to play save, close handles as soon as possible. For recursing directories, read the entire content, close the handle, and only then, process the content. Of course, this may need more memory.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: script fails with perl 5.004_02 by afoken
in thread script fails with perl 5.004_02 by harangzsolt33

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.