1N/A#
1N/A# This library is no longer being maintained, and is included for backward
1N/A# compatibility with Perl 4 programs which may require it.
1N/A#
1N/A# In particular, this should not be used as an example of modern Perl
1N/A# programming techniques.
1N/A#
1N/A# Suggested alternative: FileCache
1N/A
1N/A# Open in their package.
1N/A
1N/Asub cacheout'open {
1N/A open($_[0], $_[1]);
1N/A}
1N/A
1N/A# Close as well
1N/A
1N/Asub cacheout'close {
1N/A close($_[0]);
1N/A}
1N/A
1N/A# But only this sub name is visible to them.
1N/A
1N/Asub cacheout {
1N/A package cacheout;
1N/A
1N/A ($file) = @_;
1N/A if (!$isopen{$file}) {
1N/A if (++$numopen > $maxopen) {
1N/A local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
1N/A splice(@lru, $maxopen / 3);
1N/A $numopen -= @lru;
1N/A for (@lru) { &close($_); delete $isopen{$_}; }
1N/A }
1N/A &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
1N/A || die "Can't create $file: $!\n";
1N/A }
1N/A $isopen{$file} = ++$seq;
1N/A}
1N/A
1N/Apackage cacheout;
1N/A
1N/A$seq = 0;
1N/A$numopen = 0;
1N/A
1N/Aif (open(PARAM,'/usr/include/sys/param.h')) {
1N/A local($_, $.);
1N/A while (<PARAM>) {
1N/A $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
1N/A }
1N/A close PARAM;
1N/A}
1N/A$maxopen = 16 unless $maxopen;
1N/A
1N/A1;