我希望@list包含$ root_dir中匹配*YYYYMMDD*的所有文件名,其中YYYYMMDD是25小时前.
我试试......
my ($y, $m, $d) = (localtime(time - 25 * 60 * 60))[5,4,3];
my $pattern = sprintf('*%4d%02d%02d*',$y+1900,$m+1,$d);
print "The pattern is $pattern\n";
my @files = <$pattern>;
foreach (@files) {
print "$_\n";
}
Run Code Online (Sandbox Code Playgroud)
...但是我没有获取文件列表,而是在未打开的文件句柄上获得readline().
我知道<>运算符可以解释变量,因此<$ y $ m $ d>将在一年中最后三个月的三分之二天内工作,因为那些将是有两位数的月和日,但是不稳健.
我必须写...
$m = sprintf('%02d',$m+1);
$d = sprintf('%02d',$d+1);
my @files = <*$y$m$d*>;
Run Code Online (Sandbox Code Playgroud)
......还是有更简洁的东西?就像是 ...
# invalid code unless you want to produce the string "readline() on unopened filehandle" for some reason
my @files = <sprintf('*%4d%02d%02d*',$y+1900,$m+1,$d)>;
Run Code Online (Sandbox Code Playgroud)
使用
my @files = glob($pattern);
Run Code Online (Sandbox Code Playgroud)
该<...>运营商是太超负荷了.具体来说,<$...>被视为文件句柄.
| 归档时间: |
|
| 查看次数: |
324 次 |
| 最近记录: |