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(<*>);
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: