in reply to Re: Re: Re: Re: Sort problem
in thread Sort problem

Try it with this sample data, for example:

@in = ( ['the cat sat'], ['the ', 'cat', 'sat'], ['the cat', 'sat'], ['the', 'cat', 'sat'], );

I would expect it to be sorted 4, 2, 3, 1. Concatenating and compressing the spaces, then using the ST returns the array in its original order.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Sort problem
by tachyon (Chancellor) on Feb 26, 2003 at 20:48 UTC

    If that is the problem (hard to tell from the post) then all you need is $" = '';

    @in = ( ['the cat sat'], ['the ', 'cat', 'sat'], ['the cat', 'sat'], ['the', 'cat', 'sat'], ); { local $" = ''; @out = sort { "@$b" cmp "@$a" } @in; } use Data::Dumper; # munge the output for compactness and to make it look nicer $Data::Dumper::Indent = 0; print map {s/\[/\n \[/g; $_} Dumper \@out; __DATA__ $VAR1 = [ ['the','cat','sat'], ['the ','cat','sat'], ['the cat','sat'], ['the cat sat']];

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print