是否能保证 Perl 中的通配结果会被排序?
是否可以保证从 glob 返回的文件名数组(例如 <*>
)将被排序?
我找不到文档中提到的一种或另一种排序方式,但是我尝试过的每个目录似乎都是这种情况。
我正在谈论使用这种语法:
@files = <*>;
如果我需要对文件进行排序,下面的内容会是多余的吗?
@files = sort(<*>);
Is there any guarantee that the array of filenames returned from a glob (e.g. <*>
) will be sorted?
I can't find that sorting is mentioned one way or the other in the documentation, but it seems to be the case in every directory I've tried it on.
I'm talking about using this syntax:
@files = <*>;
If I need the files to be sorted, would the below be redundant?
@files = sort(<*>);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Perl 5.6.0 及更高版本中,文件名是排序的:
-- glob 的 perldoc
-- perldoc for File::Glob
有一个问题:
-- perldoc for File::Glob
说了这么多,您可以更改此行为不区分大小写地排序,请
注意:全局自 5.6.0 以来是多余的,但这也适用于旧版本。
或者,如果您只想执行不区分大小写的单个 glob:
In Perl 5.6.0 and newer, filenames are sorted:
-- perldoc for glob
-- perldoc for File::Glob
There is one catch:
-- perldoc for File::Glob
Having said all that, you can change this behavior to sort case-insensitively with
Note that :globally is redundant since 5.6.0, but this will work on older versions as well.
Alternately, if you just want to do a single glob with case-insensitivity: