From: "Ara.T.Howard" Date: 2005-10-11T06:55:09+09:00 Subject: Re: Sort pseudo-lists On Tue, 11 Oct 2005, pete boardman wrote: > Say I've got a string like this: > > "{{3.1, 1.3, 2.5, 2.1}, {2.1, 3.1, 2.4, 2.2}, {1.4, 2.2, 2.1, 4.2}}" > > - imagine it's aspiring to be a list of sublists, with 4 reals in each list. > I want to produce a sorted version: > > (1.4 2.2 2.1 4.2) > (2.1 3.14 2.4 2.2) > (3.1 1.3 2.5 2.1) > > What would be a good way to do this? harp:~ > cat a.rb buf = "{{3.1, 1.3, 2.5, 2.1}, {2.1, 3.1, 2.4, 2.2}, {1.4, 2.2, 2.1, 4.2}}" buf.gsub! %r/ { /x, ' [ ' buf.gsub! %r/ } /x, ' ] ' require 'yaml' list = YAML::load(buf).map{|s| s.sort}.sort p list harp:~ > ruby a.rb [[1.3, 2.1, 2.5, 3.1], [1.4, 2.1, 2.2, 4.2], [2.1, 2.2, 2.4, 3.1]] -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================