in reply to Sorting path like strings

sub do_the_sort { my @aa = split /\//, $a; my @bb = split /\//, $b; for ( 0 .. $#aa ) { return 1 unless defined $bb[$_]; my $zz = $aa[$_] <=> $bb[$_]; return $zz if $zz; } -1; } my @y = sort do_the_sort @x;
Boris

Replies are listed 'Best First'.
Re^2: Sorting path like strings
by Limbic~Region (Chancellor) on Jan 05, 2006 at 16:49 UTC
    borisz,
    I think the following recursive implementation does basically the same thing - don't ask me how I came up with it.
    my @data = map {chomp; [ split '/' ] } <DATA>; @data = map { join '/', @$_ } sort my_sort @data; sub my_sort { my $i = shift || 0; if ( defined $a->[$i] && defined $b->[$i] ) { return $a->[$i] <=> $b->[$i] || my_sort(++$i); } return defined $a->[$i] ? 1 : -1; }

    Cheers - L~R