简体   繁体   English

Strawberry Perl-在Windows中搜索和替换

[英]Strawberry Perl - Search and replace in Windows

I am trying to execute the following command: 我正在尝试执行以下命令:

perl -pi -e 's,vaadin-element,color-picker,g' *.* demo/* test/* src/* theme/*/*
(following this document) (遵循文件)

Unfortunately it seems that the window distribution of pearl I use has some issues with the command, as I get the following error: 不幸的是,我得到的以下错误似乎使我使用的Pearl的窗口分布与命令存在一些问题:

Can't open *.*: Invalid argument.
Can't open demo/*: Invalid argument.
Can't open test/*: Invalid argument.
Can't open src/*: Invalid argument.
Can't open theme/*/*: Invalid argument.

Any suggestions on how to fix that? 关于如何解决该问题的任何建议? Thank you in advance! 先感谢您!

Disclaimer: I never used pearl before and have absolutely no experience. 免责声明: 我以前从未使用过Pearl,而且绝对没有经验。

In unix systems, the shell expands globs and passes the file names to the program. 在unix系统中,shell扩展glob并将文件名传递给程序。

$ perl -e'CORE::say for @ARGV' *
file1
file2

The Windows shell, on the other hand, passes the values as is, and leaves it up to the program to treat them as globs if so desired. 另一方面,Windows shell照原样传递值,然后将其留给程序以将它们视作glob(如果需要)。

>perl -e"CORE::say for @ARGV" *
*

You can perform the globbing as follows: 您可以按照以下步骤进行通配:

>perl -MFile::DosGlob=glob -e"BEGIN { @ARGV = map glob, @ARGV } CORE::say for @ARGV" *
file1
file2

The BEGIN block isn't generally needed, but it will ensure the globing once and early enough when using -n (which is implied by -p ). 通常不需要BEGIN块,但是它将确保在使用-n (由-p隐含)时进行一次足够早的定位。

The -MFile::DosGlob=glob makes glob have Windows-like semantics. -MFile::DosGlob=glob使glob具有类似于Windows的语义。 For example, it causes *.* to match all files, even if they don't contain . 例如,它使*.*匹配所有文件,即使它们不包含. .

Integrated: 集成:

perl -i -MFile::DosGlob=glob -pe"BEGIN { @ARGV = map glob, @ARGV } s,vaadin-element,color-picker,g" *.* demo/* test/* src/* theme/*/*

In Unix-derived operating systems, the shell expands globs like *.* , and provides the command line as an array of strings to the program. 在源自Unix的操作系统中,shell扩展了*.*类的glob,并将命令行作为字符串数组提供给程序。

In Windows, the command line is a single string, and it is up to the program to interpret what it means, including things like quote characters and globs. 在Windows中,命令行是单个字符串,由程序来解释它的含义,包括引号字符和glob之类的内容。 If the program is a normal C program, the C runtime interprets command line, and expands the globs, and passes an array of strings to main . 如果程序是普通的C程序,则C运行时将解释命令行,扩展glob,并将字符串数组传递给main This is because the C standard requires this. 这是因为C标准要求这样做。

However Perl is not C. Use the File::Glob library to expand the arguments. 但是Perl不是C。使用File::Glob库来扩展参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM