43、实现一个子例程,用于收集修改时间在两个给定时间戳之间的文件。
以下是实现该功能的子例程:
sub gather_mtime_between {
my($begin, $end) = @_;
my @files;
my $gatherer = sub {
my $timestamp = (stat $_)[9];
unless (defined $timestamp) {
warn "Can't stat $File::Find::name: $!, skipping\n";
return;
}
push @files, $File::Find::name if $timestamp >= $begin and $timestamp <= $end;
};
my $fetcher = sub {
@files
};
return ($gatherer, $fetcher);
}
该子例程接受两个时间戳作为参数,返回两个代码引用。第一个代码引用用于在 File::Find 中收集修改时间在这两个时间戳之间的文件,第二个代码引用用于获取收集到的文件列表。
44、编写一个程序,允许用户选择不同的输出方式(输出到文件、输出到标量或同时输出到两者)并打印相关信息。
以下是实现该功能的程序代码:
use IO::Tee;
use v5.8;
my $fh;
my $scalar;
print 'Enter type of output [Scalar/File/Tee]> ';
my $type = <STDIN>;
if( $type =~ /^s/i ) {
open $fh, '>', \$scalar;
}
elsif( $type =~ /^f/

最低0.47元/天 解锁文章
783

被折叠的 条评论
为什么被折叠?



