in reply to Re: Funky sorting
in thread Funky sorting

Yeah, that index threw me for quite a while. I think a more accurate replacement is:

@v= sort { length($a) <=> length($b) || $a cmp $b } @v;
however (sort first by length and sort strings of the same length lexigraphically).

Basically, the use of index doesn't end up changing anything since $a can only be a substring of $b if it is either shorter than $b or it is exactly equal to $b.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Funky sorting
by blakem (Monsignor) on Nov 10, 2001 at 05:03 UTC
    Ah, you're right. For some reason I thought the data being sorted would never tie, but that is obviously wrong. (The first "elements" got magically sorted in my head.... meaning length was the only defining characteristic. i.e. two strings starting with same two digits and having the same length are equal by construction.)

    -Blake

Re: (tye)Re: Funky sorting
by Anonymous Monk on Nov 10, 2001 at 05:46 UTC
    So basically I've been sitting here overcomplicating things. Damn.

    Thanks