7.17. Caching Open Output FilehandlesProblemYou need more output files open simultaneously than your system allows. SolutionUse the standard FileCache module: use FileCache; cacheout ($path); # each time you use a filehandle print $path "output"; DiscussionFileCache's The Example 7.8 splits an xferlog file created by the popular wuftpd FTP server into files named after the authenticated user. The fields in Example 7.8: splitwulog#!/usr/bin/perl
# splitwulog - split wuftpd log by authenticated user
use FileCache;
$outdir = '/var/log/ftp/by-user';
while (<>) {
unless (defined ($user = (split)[-4])) {
warn "Invalid line: $.\n";
next;
}
$path = "$outdir/$user";
cacheout $path;
print $path $_;
}See AlsoDocumentation for the standard FileCache module (also in Chapter 7 of Programming Perl); the |