Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DirHandle : the sort is different on Windows and on Linux

Reply
Thread Tools

DirHandle : the sort is different on Windows and on Linux

 
 
thierry.torret@st.com
Guest
Posts: n/a
 
      07-27-2006
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.

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      07-27-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      07-27-2006
John W. Krahn wrote:
> (E-Mail Removed) wrote:
>
>>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 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?

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      07-27-2006
On Thu, 27 Jul 2006 13:13:06 +0000, John W. Krahn wrote:

> (E-Mail Removed) wrote:
>> 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


Or use globbing.

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

M4
--
Redundancy is a great way to introduce more single points of failure.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl sort different from unix sort Jose Luis Perl Misc 3 03-03-2011 09:14 PM
Re: Is Netscape Leaving Firefox Behind on GNU/Linux? THE LINUX PROPAGANDA MACHINE CONTINUES. FIREFOX IGNORING LINUX............. traci.manicotti@gmail.com Computer Support 2 10-20-2007 02:12 PM
Selection sort and bubble sort lovecreatesbea...@gmail.com C Programming 22 10-19-2007 06:16 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments