Loopy has asked for the wisdom of the Perl Monks concerning the following question:

(newbie alert)
Here's the code: (Win2k, ActiveState Perl 5.6 bld620)
use strict; use File::Recurse; my $size = "0"; recurse(\&sizedir, "k:/node1"); print "$size\n"; exit; sub sizedir { shift; $size += -s "$_"; }

The code appears to function correctly, but I get an error "File::Recurse::recurse() called too early to check prototype at F:/Perl5.6.0/site/lib/File/Recurse.pm line 49." Here's the surrounding code from Recurse.pm:
47:>if (-d _) { 48:> next if (-l $path && !$File::Recurse::FOLLOW_SYMLINKS); 49:> $ret = recurse($exe,$path,$context,$level+1); 50:> last if ($ret == -2); 49:>}

Any ideas on what would cause this?

Replies are listed 'Best First'.
Re: Errors in File::Recurse()?
by Fastolfe (Vicar) on Nov 10, 2000 at 02:08 UTC
    Perhaps this is a bug in File::Recurse. From perldiag (5.6):
    %s() called too early to check prototype

    (W prototype) You've called a function that has a prototype before the parser saw a definition or declaration for it, and Perl could not check that the call conforms to the prototype. You need to either add an early prototype declaration for the subroutine in question, or move the subroutine definition ahead of the call to get proper prototype checking. Alternatively, if you are certain that you're calling the function correctly, you may put an ampersand before the name to avoid the warning. See the perlsub manpage.

    Is 'recurse' declared correctly (and early enough, given that it is prototyped) in Recurse.pm?

    Additionally, are you sure this is even an error? It looks to me like it's just a warning. Try removing the -w flag from your script and see if it runs OK.

RE: Errors in File::Recurse()?
by lemming (Priest) on Nov 10, 2000 at 02:57 UTC
    I don't think you want to use find::recurse if I read the module correctly. It seems to return a hash of filenames, based on your criteria. Maybe I'm looking at a different recurse?
    I get accurate results by using File::Find.
    use strict; use File::Find; my $size = "0"; find(\&sizedir, "k:/node1"); print "$size\n"; exit; sub sizedir { shift; $size += -s "$_"; }
    Hope that helps. By the way, "k:/node1" & "k:\\node1" work for ActivePerl.
    "k:\node1" checks out as:
    k:
    ode1
CPU Usage for Find vs Recurse
by Loopy (Initiate) on Nov 10, 2000 at 04:15 UTC

    I tried both the File::Find() and File::Recurse.

      Results: (2.9GB local IDE NTFS partition, PIII/833)
    • Recurse == 81 seconds; 43% avg CPU usage
    • Find == 31 seconds; 100% avg CPU usage (plus one error about "Can't opendir(f:/System Volume Information): Invalid Argument" or some such)
    Interesting difference. Over a 100mbit network, the cpu and time results were identical (obviously limited by the network, not the code).
      Found my reason for confusion. The two recurse modules are completly different.
      An alternative method of calling recurse. (Sugested by the module for simple tasks.)
      recurse {$size += -s}, "k:/node1";
Re: Errors in File::Recurse()?
by lolindrath (Scribe) on Nov 10, 2000 at 02:13 UTC
      Actually, that's not-so-much true. Within Perl (and really, for many Win32 functions), 'c:/folder' is perfectly valid.
      Or 'c:\folder\folder'. You only need to escape the back-slashes when you use them together (so you can still escape '): '\\\\server\share\dir\jack\'s file'
        Hehe...well, the unexpected behavior in this situation is that if you use a function that evaluates the path string and the first letter after a single backslash is an 'n' or some other command (e.g.: \n, etc.) then it evals that command and craps out your function. Forwardslash works fine on Win2k, dunno about other M$ products.