作者lzch (再努力一点...)
看板Perl
标题Re: [问题] 请问关於在windows 下的* 字元
时间Mon Jun 23 01:19:26 2008
※ 引述《n0tme (who did this?)》之铭言:
: 如果我下 perl -pie '...' abc.txt 可以单处理一个档
: 但是後面想接万用字元 * 处理所有的.txt档,windows会显示错误
: 之前在unix 或 windows 下的cygwin可以使用*
: 想请问windows下要怎麽一次处理多个档案呢 ?
http://www.dunwich.org/soft/wildcardext.html
Command-line Wildcard Expansion
The default command shells on DOS descendant operating systems (such as they
are) usually do not expand wildcard arguments supplied to programs. They
consider it the application's job to handle that. This is commonly achieved
by linking the application (in our case, perl) with startup code that the C
runtime libraries usually provide. However, doing that results in
incompatible perl versions (since the behavior of the argv expansion code
differs depending on the compiler, and it is even buggy on some compilers).
Besides, it may be a source of frustration if you use such a perl binary with
an alternate shell that *does* expand wildcards.
Instead, the following solution works rather well. The nice things about it
are 1) you can start using it right away; 2) it is more powerful, because it
will do the right thing with a pattern like */*/*.c; 3) you can decide
whether you do/don't want to use it; and 4) you can extend the method to add
any customizations (or even entirely different kinds of wildcard expansion).
C:\> copy con c:\perl\lib\Wild.pm
# Wild.pm - emulate shell @ARGV expansion on shells that don't
use File::DosGlob;
@ARGV = map {
my @g = File::DosGlob::glob($_) if /[*?]/;
@g ? @g : $_;
} @ARGV;
1;
^Z
C:\> set PERL5OPT=-MWild
C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
p4view/perl/perl.c
p4view/perl/perlio.c
p4view/perl/perly.c
perl5.005/win32/perlglob.c
perl5.005/win32/perllib.c
perl5.005/win32/perlglob.c
perl5.005/win32/perllib.c
perl5.005/win32/perlglob.c
perl5.005/win32/perllib.c
Note there are two distinct steps there: 1) You'll have to create Wild.pm and
put it in your perl lib directory. 2) You'll need to set the PERL5OPT
environment variable.
If you want argv expansion to be the default, just set
PERL5OPT in your default startup environment.
If you are using the Visual C compiler, you can get the C runtime's command
line wildcard expansion built into perl binary. The resulting binary will
always expand unquoted command lines, which may not be what you want if you
use a shell that does that for you. The expansion done is also somewhat less
powerful than the approach suggested above.
==
今天遇到这问题 (真不敢相信今天才遇到...)
查到这个解法,
另外还查到说,Unix-like 下可行,是因为 shell 帮我们传的关系,
换句话说,并不是 Unix-like 下可以,而是 shell dependent 的。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.122.230.41