in reply to Re: sorting tree with folders on top
in thread sorting tree with folders on top
sub sort_files { my $adir = $1 if $$a{path} =~ m/^(.*)\//; my $bdir = $1 if $$b{path} =~ m/^(.*)\//; # a and b in the same dir if ($adir eq $bdir) { if ($$a{'file'} && !$$b{'file'}) { return -1; } elsif (!$$a{'file'} && $$b{'file'}) { return 1; } return lc $$a{'path'} cmp lc $$b{'path'}; } # b in subdir of a if ($bdir =~/^$adir\// && $$a{'file'} && !$$b{'file'}) { return -1; # a in subdir of b } elsif ($adir =~/^$bdir\// && $$b{'file'} && !$$a{'file'}) { return 1; } lc $$a{'path'} cmp lc $$b{'path'}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: sorting tree with folders on top
by jethro (Monsignor) on Apr 07, 2009 at 15:31 UTC |