Wednesday, October 29, 2008

Transform a Twiki Table

I needed to change a TWiki table to make the rows become columns and columns become rows.

Ruby + 5 mins =

table = <<-TABLE
...paste table here...
TABLE

rows = (table.split "\n").collect { |line| line.split("|") }
puts (0.. rows[1].length).each { |col| puts "|#{rows.collect{ |row| row[col] }.join("|")}|" }

Ahhhh.. That could have been painful.

I love being a programmer. How do people that don't code handle this sort of problem?

1 comment:

Duncan Bayne said...

You assume that all programmers would be capable of creating a solution like yours.

Do you read the Daily WTF?

GitHub Projects