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