更新时间:2021-11-23 22:33:38
这是Windows/MS-DOS的限制.根据 perldiag :
This is a Windows/MS-DOS limitation. According to perldiag:
您正在使用MS-DOS之类的系统,如果尝试从已删除(但仍处于打开状态)的文件中进行读取,则会感到困惑.您必须说-i.bak或类似的话.
You're on a system such as MS-DOS that gets confused if you try reading from a deleted (but still opened) file. You have to say -i.bak, or some such.
Perl的-i
实现使它删除file1.txt
并同时保持打开的句柄,然后重新创建具有相同名称的文件.即使文件1.txt已被删除并正在重新创建,这也允许您读取"该文件.不幸的是,Windows/MS-DOS不允许您删除带有打开句柄的文件,因此该机制不起作用.
Perl's -i
implementation causes it to delete file1.txt
while keeping an open handle to it, then re-create the file with the same name. This allows you to 'read' file1.txt even though it has been deleted and is being re-created. Unfortunately, Windows/MS-DOS does not allow you to delete a file that has an open handle attached to it, so this mechanism does not work.
您***的选择是使用-i.bak
,然后删除备份文件.这至少为您提供了一些保护-例如,如果perl
以非零退出代码退出,则可以选择不删除备份.像这样:
Your best shot is to use -i.bak
and then delete the backup file. This at least gives you some protection - for example, you could opt not to delete the backup if perl
exits with a non-zero exit code. Something like:
perl -i.bak -ape "splice...." file1.txt && del file1.bak