我有一個提取日期時間戳的串列。從這個串列中,我想為每個日期/時間列印上午 8 點到下午 5 點之間的時間戳。但是我下面的代碼不會產生任何輸出。
資料:
2021-Sep-16 21:24:48
2021-Sep-17 03:31:05
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-17 15:50:34
2021-Sep-17 16:50:35
2021-Sep-18 03:31:05
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
2021-Sep-18 15:50:34
2021-Sep-18 22:50:35
預期輸出:
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
我的代碼:
sub read_timestamps{
my $file = './logs/file.log';
open(IN, "<" ,"$file") or die "Couldn't open file $!";
open(OUT, ">" ,"_trash/tmp/raw/0-out.txt") or die "Couldn't open file $!";
my @content = <IN>;
my $start="08:00:00";
my $end = "17:00:00";
foreach $lines(@content){
if($lines = ~/$start/../$end/){
print OUT ("$1 \n") if($lines =~ /(\d{4}-\w -\d{2} \d\d:\d\d:\d\d)/);
}
}
}
uj5u.com熱心網友回復:
while (<>) {
my ( $h ) = / (\d )/
or next;
print if $h >= 8 && $h < 17;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/381743.html
下一篇:嘗試創建Dancer2自定義回應
