Nigel Peck wrote: > > Hi, Hello,
> I have a list containing the names of all items in a directory. I want > to sort it by non-directories first and then directories, with a > secondary sort in alphabetical order. > > I currently have: > > -------------------------------- > my @items = sort { > > my $a_path = $args->{directory_from} . '\\' . $a; > my $b_path = $args->{directory_from} . '\\' . $b; > > ( -d $a_path ) ? 1 : 0; > > } readdir $directory; > -------------------------------- > > which gets me the non-directories first and directories after but not in > alphabetical order. > > I don't want to rely on the alphabetical ordering from the readdir as I > believe that Perl's sort does not guarantee to maintain ordering in > future releases? > > Can't get my head round this, please help! :) my @items = map "$args->{directory_from}/$_", do { my ( @dirs, @files ); push @{ -d "$args->{directory_from}/$_" ? [EMAIL PROTECTED] : [EMAIL PROTECTED] }, $_ for sort readdir $directory; @files, @dirs; }; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/