1
我需要搜索具有值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);
'perl -pe's /(\ d):(\ d {2}):(\ d {2})/ $ 1小時$ 2分鐘,$ 3秒/ g'infi le> outfile'也許。 – TLP
什麼是'm!/ s/[%d:%02d:%02d]/g/hacker /!'? – Borodin