使用 perl 获取上周数据的正则表达式

regex expression to fetch last week data using perl

我有一个 Perl 脚本,它将在一个 csv 文件中生成输出。 Perl 脚本按月提供输出并在每个星期四执行。请查看我放入 perl 脚本中的正则表达式。

'{"Date":{"$regex":/^(0[1-9]|[12][0-9]|3[01])-10-2017/i}}'

但是一旦生成此输出,我需要复制上周数据(例如 10 月 12 日至 18 日)并需要发送给会员。所以我想要这样的正则表达式,它会根据上周的输出向我发送一个。(上周并发)

可以生成如下所示的正则表达式:

use strict;
use warnings;

use POSIX qw/strftime/;

my $now = time;

my @dates;
push @dates, strftime "%d-%m-%Y", localtime($now - $_ * 86_400 ) for (0..6);

my $regex_string = '(' . join( '|', @dates) . ')';

希望对你有用

I am aware of the problem one could potentially have with this, when it's just after the moment Daylight Saving Time would start -- if that is really a problem, then iterate over a for loop for 13 times, with steps of 43.200 seconds, which is half a day decrements.