2009/11/5 WangKevin <kevin-w-sh@hotmail.com>:
> 直接写回去就覆盖了
>
> undef $/;
>
> open FILE, $filepath;
> $C = <FILE>;
> close FILE;
> $/="\n";
>
> $C =~ s/str1/str2/gi
>
> open( FILE, ">$filepath");
>
> print FILE $C;
> close(FILE);
>
> 你也可以试试 >+
> 打开一次看行不行
>
>
> MALA WANG
>
>
>
>
> ________________________________
> Date: Thu, 5 Nov 2009 13:40:00 +0800
> Subject: [PerlChina] Re: 请教下,perl如何在替换文件里的字符串并写回文件
> From: smallfish.xy@gmail.com
> To: perlchina@googlegroups.com
>
> 替换完直接把内容写入当前文件就可以了
> --
> http://pythonchina.org
> http://hi.baidu.com/smallfish_xy
>
>
> 2009/11/5 Nestle <zhurx4g@gmail.com>
>
> 请教下,perl如何在替换文件里的字符串并写回文件。我现在的做法是,打开一个文件,替换内容,写到新文件,最后删除旧文件,用原文件名重新命名新文
> 件,有没有直接写回的办法?我不想创建新的文件。
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---
没有评论:
发表评论