DirHandle : the sort is different on Windows and on Linux

T

thierry.torret

I use a old Perl script using Dirhandle but the sort is different on
Windows and on Linux

$dh = new DirHandle($test) || return;
while ($OneFile = $dh->read()) {

In Windows the directory and files are sorted by name : it is OK
but on Linux there are sorted in order of directory
creation/modification date but we want it by name.

Is there any option to use in Dirhandle new or read to sort by named in
all system ?

I cannot modify too much the script therefore need to keep
while ($OneFile = $dh->read()) method
and not replace it by an array of directory name.
 
J

John W. Krahn

I use a old Perl script using Dirhandle but the sort is different on
Windows and on Linux

$dh = new DirHandle($test) || return;
while ($OneFile = $dh->read()) {

In Windows the directory and files are sorted by name : it is OK
but on Linux there are sorted in order of directory
creation/modification date but we want it by name.

The DirHandle module is just an OO wrapper around Perl's built-in
opendir/readdir/rewinddir/closedir functions and these functions do not do any
sorting. If you want the results sorted you will have to do it yourself.

perldoc -f sort



John
 
J

Josef Moellers

John said:
The DirHandle module is just an OO wrapper around Perl's built-in
opendir/readdir/rewinddir/closedir functions and these functions do notdo any
sorting. If you want the results sorted you will have to do it yourself.

perldoc -f sort

Which is sensible, because if you don't want them sorted, how would you
un-sort 'em?
 
M

Martijn Lievaart

The DirHandle module is just an OO wrapper around Perl's built-in
opendir/readdir/rewinddir/closedir functions and these functions do not do any
sorting. If you want the results sorted you will have to do it yourself.

perldoc -f sort

Or use globbing.

for my $OneFile (glob($test)) {

M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top