1
값이 h : mm : ss 인 태그를 검색하고이 값을 h 시간, mm 분 및 ss 초로 대체하여 출력 파일에 저장해야합니다.특정 태그를 검색하고 해당 값을 바꿉니다.
저는 replace 구문으로 고민하고 있습니다. 지금 나는 입력 파일을 읽고있다. 이 $newh
, $newmin
및 $newsec
는 각각 시간, 분, 초에 대한 새로운 값은 가정 :
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})/$ 1 시간 $ 2 분 및 $ 3 초/g'infi le> outfile'. – TLP
'm/s/[% d : % 02d : % 02d]/g/hacker /! '란 무엇입니까? – Borodin