X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fcacheout.pl;h=d2669a1cfa82f60c16250250790eae66f0c640ca;hb=4bd7b839c96352aa075f714f4c1aaa963c29018e;hp=106014cc5d3a10d8b4b290c9a1695a806f508b35;hpb=39c3038ca76b338006c640ae6da52b407dd9e654;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/cacheout.pl b/lib/cacheout.pl index 106014c..d2669a1 100644 --- a/lib/cacheout.pl +++ b/lib/cacheout.pl @@ -1,4 +1,11 @@ -#!/usr/bin/perl +# +# This library is no longer being maintained, and is included for backward +# compatibility with Perl 4 programs which may require it. +# +# In particular, this should not be used as an example of modern Perl +# programming techniques. +# +# Suggested alternative: FileCache # Open in their package. @@ -6,20 +13,24 @@ 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 +44,9 @@ $seq = 0; $numopen = 0; if (open(PARAM,'/usr/include/sys/param.h')) { - local($.); + local($_, $.); while () { - $maxopen = $1 - 4 if /^#define NOFILE\s+(\d+)/; + $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/; } close PARAM; }