I don't think trying to bracket the hires time with lores
[p5sagit/p5-mst-13.2.git] / lib / cacheout.pl
CommitLineData
a6d71656 1#
2# This library is no longer being maintained, and is included for backward
3# compatibility with Perl 4 programs which may require it.
4#
5# In particular, this should not be used as an example of modern Perl
6# programming techniques.
7#
8# Suggested alternative: FileCache
9
39c3038c 10# Open in their package.
11
12sub cacheout'open {
13 open($_[0], $_[1]);
14}
15
a0d0e21e 16# Close as well
17
18sub cacheout'close {
19 close($_[0]);
20}
21
39c3038c 22# But only this sub name is visible to them.
23
24sub cacheout {
25 package cacheout;
26
27 ($file) = @_;
39c3038c 28 if (!$isopen{$file}) {
29 if (++$numopen > $maxopen) {
55204971 30 local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
39c3038c 31 splice(@lru, $maxopen / 3);
32 $numopen -= @lru;
a0d0e21e 33 for (@lru) { &close($_); delete $isopen{$_}; }
39c3038c 34 }
35 &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
36 || die "Can't create $file: $!\n";
37 }
38 $isopen{$file} = ++$seq;
39}
40
41package cacheout;
42
43$seq = 0;
44$numopen = 0;
45
46if (open(PARAM,'/usr/include/sys/param.h')) {
7adad424 47 local($_, $.);
39c3038c 48 while (<PARAM>) {
55204971 49 $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
39c3038c 50 }
51 close PARAM;
52}
53$maxopen = 16 unless $maxopen;
54
551;