From: Jeff Leggett Date: 2009-05-03T05:27:57+09:00 Subject: n00b ? re: CGI Hash and arrays Hi, n00b here, and got myself stumped on something I thought was easy. I get CGI params returned as: params: {"conf_mod"=>["20"], "conf_impact"=>["10"], "avail_impact"=>["5"], "integrity_impact"=>["5"], "authorization"=>["5"], "integrity_mod"=>["5"]} I just want to add up the values in the hash keys. Seems simple, but an hour or so later, after trying numerous things no go. Any help appreciated. #!/usr/bin/ruby require "cgi" cgi = CGI.new('html4') values = cgi.params #values.each_value { |y| total += (eval y.join('+')) } #values.each_value { |x| total += x[0] } #values.each_value do |v| puts v end #cgi.header cgi.out() do cgi.html() do cgi.head{ cgi.title{"TITLE"} } + cgi.body() do cgi.pre() do CGI::escapeHTML( "params: " + cgi.params.inspect + "\n" "total: " + puts(total) + "\n" ) end end end end -- Posted via http://www.ruby-forum.com/.