DirHandle : the sort is different on Windows and on Linux

Discussion in 'Perl Misc' started by thierry.torret@st.com, Jul 27, 2006.

  1. Guest

    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.
     
    , Jul 27, 2006
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Jul 27, 2006
    #2
    1. Advertising

  3. John W. Krahn wrote:
    > 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
     
    Josef Moellers, Jul 27, 2006
    #3
  4. On Thu, 27 Jul 2006 13:13:06 +0000, John W. Krahn wrote:

    > 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.
     
    Martijn Lievaart, Jul 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JAVA Rookie
    Replies:
    2
    Views:
    450
    Java, Linux and Life
    Dec 31, 2003
  2. CharlesRiver
    Replies:
    0
    Views:
    417
    CharlesRiver
    Apr 3, 2006
  3. Tim Williams
    Replies:
    2
    Views:
    447
    Tim Williams
    Feb 26, 2004
  4. Navin
    Replies:
    1
    Views:
    763
    Ken Schaefer
    Sep 9, 2003
  5. Jose Luis

    Perl sort different from unix sort

    Jose Luis, Mar 3, 2011, in forum: Perl Misc
    Replies:
    3
    Views:
    384
    Steve C
    Mar 3, 2011
Loading...

Share This Page