"is there any guarantee that results of globbing will be sorted in perl?" Code Answer

4

in perl 5.6.0 and newer, filenames are sorted:

beginning with v5.6.0, this operator is implemented using the standard file::glob extension.

-- perldoc for glob

by default, the pathnames are sorted in ascending ascii order.

-- perldoc for file::glob

there is one catch:

by default, file names are assumed to be case sensitive

-- perldoc for file::glob

having said all that, you can change this behavior to sort case-insensitively with

use file::glob qw(:globally :nocase);

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:

use file::glob ':glob';

@files = bsd_glob('*', glob_nocase);
By Murali on March 29 2022

Answers related to “is there any guarantee that results of globbing will be sorted in perl?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.