[Milo Thurston <nospam / linacreschoolofdefence.org>, 2004-06-02 11.03 CEST]
> I am attempting to convert a script that produces csv output into
> a CGI script that will produce an html table. The following code
> is the best I can think of (shown here with an example of the
> data):
> 
> switch_summary = ["1,2,3,4,5","6,7,8,9,10","11,12,13,14,15"]
> 
> # example output
> cgi.out do
> 	cgi.html do
> 	cgi.head { "\n"+ cgi.title{"Title"} + "\n" } +
> 	cgi.body {
> 		cgi.h1 { "A pox on cgi scripting"} + 
> 		cgi.table {
> 			switch_summary.each do |val|
> 				cgi.tr {
> 					val.split(",").to_a.each do |l|
> 						cgi.td {"#{l}"}
> 					end
> 				} + "\n"
> 			end
> 		}
> 	}
> 	end
> end

#each returns the original array. The block is used for side-effects. To get
an array with each element modified by the block, use #collect.

cgi.table {
	switch_summary.collect do |val|
		cgi.tr {
			val.split(",").collect do |l|
				cgi.td { l }
			end
		} + "\n"
	end
}	

HTH