From: "James F. Hranicky" Date: 2003-09-16T23:57:10+09:00 Subject: Re: scrambler one-liner On Tue, 16 Sep 2003 23:28:01 +0900 Xavier Noria wrote: > It seems one-liners are not at the heart of the Ruby community, but hey, > that's funny in the end. Can you shorten it? *shrug* I use ruby for my one liners all the time... % ruby -e 'p File.stat("/etc/passwd").mtime' Fri May 30 15:17:19 EDT 2003 or more horribly % ruby -rdbi -e 'rows = []; DBI.connect("dbi:Pg:somedb:localhost", "postgres", "XXXXX") { |dbi| dbi.prepare("select cisco, cisco_slot, cisco_port, liu_number, liu_port, floor from new_fiberx where cisco is not null and cisco_slot is not null and cisco_port is not null and liu_number is not null and liu_port is not null order by cisco, cisco_slot, cisco_port") { |sth| sth.execute; sth.each {|row| rows << row.clone } ; rows.sort_by { |row| [ row[0], row[1].to_i, row[2].to_i ] }.each { |row| next if row[0] == "" ; printf "%s.%s/%d : %d.%s/%-5s\n", row[0], row[1], row[2], row[5], row[3], row[4] }}}' etc... Jim