On Wed 07 Aug 2002 at 09:22:24 +0900, David Alan Black wrote:

> > $/ = nil
> > foo = gets.split("\n")
> > r = /^([a-z]+)([0-9]+)$/
> > foo = foo.sort {|a,b| c,d = r.match(a)[1,2]
> >                       e,f = r.match(b)[1,2]
> >                       c <=> e or d.to_i <=> f.to_i}
> > puts foo
> >
> > [doesn't work]
> 
> It's because <=> returns -1, 0, or 1, all of which are true in
> Ruby.

And, of course, I know about those values not returning truth in Ruby,
but it continues to bite me when I'm least expecting it.

This is one of those few areas where I think the Perl way actually
makes more sense.

> You could drop in this last line of the sort:
> 
>   (c == e) and (d.to_i <=> f.to_i) or (c <=> e)}

Thanks.

Ian
-- 
Ian Macdonald               | No house should ever be on any hill or on
ian / caliban.org             | anything.  It should be of the hill,
                            | belonging to it.   -- Frank Lloyd Wright 
                            | 
                            |