Re: Wild.pmとスペースいりファイル名の問題
林です。
IIJIMA Hiromitsu wrote:
> 次に、
> C:\> perl -MWild -e "print qq'@ARGV'" "C:\Program Files\*"
> とすると、
> (1) の環境では C:\Program Files\*
> (2) の環境では C:./\Program Files\*
> という出力が出ます。
>
> Wild.pm は File::DosGlob を使っていますが、これのバグなのでしょうか?
File::DosGlob のドキュメントに
*.dll')" globs all filenames that end in ".exe" or ".dll". If you
want
to put in literal spaces in the glob pattern, you can escape them
with
either double quotes, or backslashes. e.g. "glob('c:/"Program
Files"/*/*.dll')", or "glob('c:/Program\ Files/*/*.dll')". The argument
is tokenized using "Text::ParseWords::parse_line()", so see
Text::ParseWords for details of the quoting rules used.
とあり、Text::ParseWords のドキュメントには
backslashes, etc.) are kept in the tokens. If $keep is false then
the
&*quotewords() functions remove all quotes and backslashes that are
not
themselves backslash-escaped or inside of single quotes (i.e.,
とあるのでこれに従って
C:\>perl -MWild -e "print qq'@ARGV'" "C:\\Program\ Files\\*"
としたところ、ファイル名が多数出力されました。
(Windows 2000 & ActivePerl build 811)
ちなみに PERL_SRC/win32/Makefile の
# uncomment to enable linking with setargv.obj under the Visual C
# compiler. Setting this options enables perl to expand wildcards in
# arguments, but it may be harder to use alternate methods like
# File::DosGlob that are more powerful. This option is supported
only with
# Visual C.
#
#USE_SETARGV = define
を有効にし、VC6 でコンパイルした perl では
C:\> perl -e "print qq'@ARGV'" "C:\Program Files\*"
C:\Program Files\*
C:\> perl -e "print qq'@ARGV'" "C:\\Program\ Files\\*"
C:\\Program\ Files\\*
C:\> perl -e "print qq'@ARGV'" "C:\windows\*"
C:\windows\*
C:\> perl -e "print qq'@ARGV'" C:\windows\*
(ファイル名がたくさん)
となりました。
--
林拓美(Takumi Hayashi)
Fnews-brouse 1.9(20180406) -- by Mizuno, MWE <mwe@ccsf.jp>
GnuPG Key ID = ECC8A735
GnuPG Key fingerprint = 9BE6 B9E9 55A5 A499 CD51 946E 9BDC 7870 ECC8 A735