in reply to date as part of filename
Since your dates are already in a format that is easily sorted, just use a simple '>' comparison to the one week ago date value.
use DateTime; use strict; use warnings; my $oneweekago = DateTime->now()->subtract(days => 7)->strftime("%Y%m% +d"); while (<DATA>) { print if /(\d{8})/ && $1 > $oneweekago; } =prints abcd3.20110509-2345 =cut __DATA__ abcd1.20110429-2345 abcd2.20110502-2345 abcd3.20110505-2345 abcd3.20110509-2345
Update: Changed implementation from POSIX to DateTime per ikegami
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: date as part of filename
by ikegami (Patriarch) on May 12, 2011 at 22:58 UTC | |
by wind (Priest) on May 12, 2011 at 23:21 UTC | |
by zac_carl (Acolyte) on May 15, 2011 at 02:24 UTC | |
by ikegami (Patriarch) on May 15, 2011 at 05:49 UTC |