[PerlChina] China-pm Digest, Vol 44, Issue 6

owen nirvana freeespeech at gmail.com
Mon Dec 8 21:35:08 PST 2008


谢谢
gtalk:freeespeech at gmail.com



2008/12/9  <china-pm-request at pm.org>:
> Send China-pm mailing list submissions to
>        china-pm at pm.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.pm.org/mailman/listinfo/china-pm
> or, via email, send a message with subject or body 'help' to
>        china-pm-request at pm.org
>
> You can reach the person managing the list at
>        china-pm-owner at pm.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of China-pm digest..."
>
>
> Today's Topics:
>
>   1. Re:  China-pm Digest, Vol 44, Issue 5 (owen nirvana)
>   2. Re:  文件描述符如何同时读写(
>      以不使用<>的方式更新文件 ) ( 杨溪 )
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 8 Dec 2008 09:54:34 +0800
> From: "owen nirvana" <freeespeech at gmail.com>
> Subject: Re: [PerlChina] China-pm Digest, Vol 44, Issue 5
> To: china-pm at pm.org
> Message-ID:
>        <ba5829cc0812071754v6f146a60m3f0f5ffa3f24ffe2 at mail.gmail.com>
> Content-Type: text/plain; charset=GB2312
>
> 谢谢,xargs和sed的方式也是可以,不过好像对复杂的目录名,带各种符号的,不大有效
>
> perl 填充ARGV的方式确实可以,还有个疑问,为什么perl不直接提供读加更新的方式呢,
> gtalk:freeespeech at gmail.com
>
>
>
> 2008/12/8  <china-pm-request at pm.org>:
>> Send China-pm mailing list submissions to
>>        china-pm at pm.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>        http://mail.pm.org/mailman/listinfo/china-pm
>> or, via email, send a message with subject or body 'help' to
>>        china-pm-request at pm.org
>>
>> You can reach the person managing the list at
>>        china-pm-owner at pm.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of China-pm digest..."
>>
>>
>> Today's Topics:
>>
>>   1.  文件描述符如何同时读写(
>>      以不使用<>的方式更新文件 ) (owen nirvana)
>>   2. Re:  文件描述符如何同时读写(
>>      以不使用<>的方式更新文件 ) (agentzh)
>>   3. Re:  文件描述符如何同时读写(
>>      以不使用<>的方式更新文件 ) (joe jiang)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Sun, 7 Dec 2008 19:06:03 +0800
>> From: "owen nirvana" <freeespeech at gmail.com>
>> Subject: [PerlChina] 文件描述符如何同时读写(
>>        以不使用<>的方式更新文件 )
>> To: china-pm at pm.org
>> Message-ID:
>>        <ba5829cc0812070306t291024eyb28f95258625db37 at mail.gmail.com>
>> Content-Type: text/plain; charset=GB2312
>>
>> 我想批量替换某些文件的内容,按照learning perl 的方法可以从命令行读入,但是这种情况似乎并不适用于目录嵌套的情况,
>>
>> # from learning perl
>> $^I = ".bak"
>> while (<>) {
>> s/A/B/;
>> print;
>> }
>>
>> #my code
>>
>>
>> $^I = '';
>> if ( $filename =~ /AAA/i  ) {
>> open FILE, "<", $filename or die "bla bla bla...";
>> while (<FILE>) {
>>  s/A/B/;
>>  print;
>> }
>> }
>>
>>
>>
>> 这样还是仅仅打印到STDOUT了,该如何解决,谢谢
>>
>> 注:文件分布于个子目录之下,我是用File::Find遍历查找的,这样的话就只可以使用<FILE>了,为了更灵活一些,我也觉得把一切筛选工作让命令行来解决并不太合适
>> gtalk:freeespeech at gmail.com
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Sun, 7 Dec 2008 19:34:15 +0800
>> From: agentzh <agentzh at gmail.com>
>> Subject: Re: [PerlChina] 文件描述符如何同时读写(
>>        以不使用<>的方式更新文件 )
>> To: china-pm at pm.org
>> Message-ID:
>>        <c711ff240812070334l75de64f5t2395a2dc586503b at mail.gmail.com>
>> Content-Type: text/plain; charset="gb2312"
>>
>> 2008/12/7 owen nirvana <freeespeech at gmail.com>
>>
>>> 我想批量替换某些文件的内容,按照learning perl 的方法可以从命令行读入,但是这种情况似乎并不适用于目录嵌套的情况,
>>>
>>
>> 在 *NIX 下,我一般会这么写:
>>
>> $ find /some/dir -name '*.foo' | xargs ./my-script.pl
>>
>> 对于常见的正则可以搞定的批量替换,我一般会直接使用 sed -i 's/foo/bar/g',必要时辅之以 find 命令 :)
>>
>> 如果希望 native Win32 也好使,使用 File::Find 挺好的,呵呵。如果自己用 opendir/readdir 啥的遍历目录树。
>>
>> 文件的修改,通常的做法是,先读取文件 foo,然后把修改后的写到一个临时文件中,写完之后,再把临时文件覆盖掉原始文件 foo。
>>
>> 如果 foo 不是很大,可以一口气先读到 RAM 中来,关闭掉读句柄,再以写方式打开 foo,把东西再写进 foo
>> 文件里。但这种方法存在丢数的风险,假设程序在写 foo 的过程中掉电,或者被 Ctrl-C
>> 了,那么我们就丢失了数据。所以对于比较严肃的事情,一般不推荐,呵呵 :)
>>
>> Bye,
>> -agentzh
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <http://mail.pm.org/pipermail/china-pm/attachments/20081207/8533705f/attachment-0001.html>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Sun, 07 Dec 2008 20:01:21 +0800
>> From: joe jiang <lamp.purl at gmail.com>
>> Subject: Re: [PerlChina] 文件描述符如何同时读写(
>>        以不使用<>的方式更新文件 )
>> To: china-pm at pm.org
>> Message-ID: <1228651281.10712.0.camel at flatpan>
>> Content-Type: text/plain; charset=utf-8
>>
>> 应该可以用 File::Find 的结果来填充 @ARGV,然后 print 就能配合 $^I 完成你
>> 需要的修改了。
>>
>> On 日, 2008-12-07 at 19:06 +0800, owen nirvana wrote:
>>> 我想批量替换某些文件的内容,按照learning perl 的方法可以从命令行读入,但是这种情况似乎并不适用于目录嵌套的情况,
>>>
>>> # from learning perl
>>> $^I = ".bak"
>>> while (<>) {
>>> s/A/B/;
>>> print;
>>> }
>>>
>>> #my code
>>>
>>>
>>> $^I = '';
>>> if ( $filename =~ /AAA/i  ) {
>>> open FILE, "<", $filename or die "bla bla bla...";
>>> while (<FILE>) {
>>>   s/A/B/;
>>>  print;
>>> }
>>> }
>>>
>>>
>>>
>>> 这样还是仅仅打印到STDOUT了,该如何解决,谢谢
>>>
>>> 注:文件分布于个子目录之下,我是用File::Find遍历查找的,这样的话就只可以使用<FILE>了,为了更灵活一些,我也觉得把一切筛选工作让命令行来解决并不太合适
>>> gtalk:freeespeech at gmail.com
>>> _______________________________________________
>>> China-pm mailing list
>>> China-pm at pm.org
>>> http://mail.pm.org/mailman/listinfo/china-pm
>>
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> China-pm mailing list
>> China-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/china-pm
>>
>> End of China-pm Digest, Vol 44, Issue 5
>> ***************************************
>>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 8 Dec 2008 19:21:56 +0800
> From: " 杨溪 " <blackkensai at gmail.com>
> Subject: Re: [PerlChina] 文件描述符如何同时读写(
>        以不使用<>的方式更新文件 )
> To: china-pm at pm.org
> Message-ID:
>        <d6d290370812080321n700c7e9dob36e340e22987229 at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 替换文件内容可以用Tie::File.
> 很好用的,看下perldoc的例子就知道了。对数组的操作就可以直接替换文件。
> 可以用File::Find来search应该替换哪个文件,用Tie::File来修改文件内容。
>
> 2008/12/7 joe jiang <lamp.purl at gmail.com>
>
>> 应该可以用 File::Find 的结果来填充 @ARGV,然后 print 就能配合 $^I 完成你
>> 需要的修改了。
>>
>> On 日, 2008-12-07 at 19:06 +0800, owen nirvana wrote:
>> > 我想批量替换某些文件的内容,按照learning perl 的方法可以从命令行读入,但是这种情况似乎并不适用于目录嵌套的情况,
>> >
>> > # from learning perl
>> > $^I = ".bak"
>> > while (<>) {
>> > s/A/B/;
>> > print;
>> > }
>> >
>> > #my code
>> >
>> >
>> > $^I = '';
>> > if ( $filename =~ /AAA/i  ) {
>> > open FILE, "<", $filename or die "bla bla bla...";
>> > while (<FILE>) {
>> >   s/A/B/;
>> >  print;
>> > }
>> > }
>> >
>> >
>> >
>> > 这样还是仅仅打印到STDOUT了,该如何解决,谢谢
>> >
>> >
>> 注:文件分布于个子目录之下,我是用File::Find遍历查找的,这样的话就只可以使用<FILE>了,为了更灵活一些,我也觉得把一切筛选工作让命令行来解决并不太合适
>> > gtalk:freeespeech at gmail.com <gtalk%3Afreeespeech at gmail.com>
>> > _______________________________________________
>> > China-pm mailing list
>> > China-pm at pm.org
>> > http://mail.pm.org/mailman/listinfo/china-pm
>>
>> _______________________________________________
>> China-pm mailing list
>> China-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/china-pm
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.pm.org/pipermail/china-pm/attachments/20081208/d8ca18aa/attachment-0001.html>
>
> ------------------------------
>
> _______________________________________________
> China-pm mailing list
> China-pm at pm.org
> http://mail.pm.org/mailman/listinfo/china-pm
>
> End of China-pm Digest, Vol 44, Issue 6
> ***************************************
>


More information about the China-pm mailing list