This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
cygwin32 update (untested adaptation of patch against 5.005_03)
[perl5.git] / lib / cacheout.pl
index 106014c..64378cf 100644 (file)
@@ -1,25 +1,27 @@
-#!/usr/bin/perl
-
 # Open in their package.
 
 sub cacheout'open {
     open($_[0], $_[1]);
 }
 
+# Close as well
+
+sub cacheout'close {
+    close($_[0]);
+}
+
 # But only this sub name is visible to them.
 
 sub cacheout {
     package cacheout;
 
     ($file) = @_;
-    ($package) = caller;
     if (!$isopen{$file}) {
        if (++$numopen > $maxopen) {
-           sub byseq {$isopen{$a} != $isopen{$b};}
-           local(@lru) = sort byseq keys(%isopen);
+           local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
            splice(@lru, $maxopen / 3);
            $numopen -= @lru;
-           for (@lru) { close $_; delete $isopen{$_}; }
+           for (@lru) { &close($_); delete $isopen{$_}; }
        }
        &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
            || die "Can't create $file: $!\n";
@@ -33,9 +35,9 @@ $seq = 0;
 $numopen = 0;
 
 if (open(PARAM,'/usr/include/sys/param.h')) {
-    local($.);
+    local($_, $.);
     while (<PARAM>) {
-       $maxopen = $1 - 4 if /^#define NOFILE\s+(\d+)/;
+       $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
     }
     close PARAM;
 }