Hello --

On Wed, 7 Aug 2002, Ian Macdonald wrote:

> Hi,
>
> I have a file with data like this:
>
> ina1
> ina15
> inb12
> ina9
> inc10
> inda12
> inef14
> inab14
> inzz8
> inzz80
> inzz9
>
> etc.
>
> I want to sort it alphabetically on the first part of the string, then
> numerically on the second part.
> $/ = 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.

You could drop in this last line of the sort:

  (c == e) and (d.to_i <=> f.to_i) or (c <=> e)}


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav