【发布时间】:2020-08-26 23:11:17
【问题描述】:
我对 Perl 脚本有一些疑问。它修改文件的内容,然后重新打开它来写入,在此过程中会丢失一些字符。从文件中删除所有以“%”开头的单词。这很烦人,因为 % 表达式是对话框的变量占位符。
你知道为什么吗?源文件是默认编码的 XML
代码如下:
undef $/;
open F, $file or die "cannot open file $file\n";
my $content = <F>;
close F;
$content =~s{status=["'][\w ]*["']\s*}{}gi;
printf $content;
open F, ">$file" or die "cannot reopen $file\n";
printf F $content;
close F or die "cannot close file $file\n";
【问题讨论】: