Perl 文件通配的奇怪现象
我正在编写一个脚本,它将循环遍历一系列数字,构建一个 glob 模式,并根据 glob 测试目录中是否存在文件。
这些图像是纳斯卡汽车号码图像,并遵循以下模式:
1_EARNHARDTGANASSI_256.TGA
2_PENSKERACING_256.TGA
这是我正在使用的脚本的片段:
foreach $currCarNum (0..101) {
if (glob("//headshot01/CARS/${currCarNum}_*_256.TGA")) {
print("Car image $currCarNum exists\n");
} else {
print("Car image $currCarNum doesn't exist\n");
}
}
我遇到的问题是目录中存在图像,并且应该与文件 glob 匹配模式没有。
例如,具有以下名称的文件将返回为不存在:
2_PENSKERACING_256.TGA
而以下名称将返回为存在:
1_EARNHARDTGANASSI_256.TGA
如果我在 DOS 或 Cygwin 中使用相同的文件 glob 模式,则两个文件都会正确列出。
文件 glob 模式在 Perl 中的解释是否不同?我有什么遗漏的吗?
I'm writing a script that will loop through a range of numbers, build a glob pattern, and test if a file exists in a directory based on the glob.
The images are Nascar car number images, and follow the the following pattern:
1_EARNHARDTGANASSI_256.TGA
2_PENSKERACING_256.TGA
Here is a snippet of the script that I am using:
foreach $currCarNum (0..101) {
if (glob("//headshot01/CARS/${currCarNum}_*_256.TGA")) {
print("Car image $currCarNum exists\n");
} else {
print("Car image $currCarNum doesn't exist\n");
}
}
The problem I'm having, is that images that exist in the directory, and that should match the file glob pattern do not.
For example, the file with the following name returns as not existing:
2_PENSKERACING_256.TGA
Whereas, the following returns as existing:
1_EARNHARDTGANASSI_256.TGA
If I use the same file glob pattern in DOS or Cygwin, both files are listed properly.
Are file glob patterns interpreted differently in Perl? Is there something I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要以列表格式而不是标量格式返回结果。尝试一下你的 if 语句,当我测试它时它对我有用。
You need to have the results returned in a list format instead of a scalar format. Try this for your if statement, it worked for me when I tested it.
来自 perldoc perlop:
From perldoc perlop: