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):
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
However, rather than producing a table with each element of the array
to a line, and each number to a separate cell it produces this:
Title
A pox on cgi
scripting
1,2,3,4,56,7,8,9,1011,12,13,14,15
I’d therefore be grateful if anyone would explain why, and also point me
in the direction of anything that explains cgi scripting without
assuming prior knowledge of Perl, for example (I was no good at cgi
scripts with that language, either).
Thanks.
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):
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
}