我需要搜索具有值 h:mm:ss 的标签,并将这个值替换为我的输出文件中的 h 小时、mm 分钟和 ss 秒。
我正在努力使用替换语法。现在写我有一个输入文件要继续阅读。
这就是我正在尝试的 -
open(my $fh, '<:encoding(UTF-8)', $filein)
or die "Could not open file '$filein' $!";
while(<$fh>) {
chomp $_;
while ( $_ =~ /<time>\s*([^<]*)\s*<\/time>/g ) {
chomp $1;
push(@time, $1);
}
}
close($fh);
open(my $wr, '<:encoding(UTF-8)', $filein)
or die "Could not open file '$filein' $!";
open(FILE, ">$fileout") or die "File not found";
print FILE "average time = 1:00:43\n";
while (my $line = <>){
$line =~ m!/s/[%d:%02d:%02d]/g/hacker/!; #hacker is my replaced value for testing purpose.
#$x =~ s/cat/hacker/;
#s/<PREF>/ABCD/g;
print FILE $line;
}
print FILE @time;
close(FILE);