From: Simon Krahnke Date: 2009-02-28T18:04:49+09:00 Subject: Re: Help with Multi Dimensional Array * lionbarrage (2009-02-27) schrieb: > Thanks! I did: > sets.keys.each{|k| > print k, "|" > } > print "\n" You could just do puts set.keys.join('|') To have the value output you specified in you original post, is a little more complicated. > Is there a format function which will remove "" and change , to | ? Don't use pp for production use. Do your own formatting. Here's my updated script: ,----[ sets.rb ] | #!/usr/bin/env ruby | | sets = Hash.new { | h, k | h[k] = [] } # hash that contains a new array | # for every new key | %w(file1.txt file2).each do | filename | | File.open(filename) do | f | | names = f.gets.chop.split('|') | f.each do | line | | names.zip(line.chop.split('|')).each do | name, value | | sets[name] << value.to_i if value and value !~ /^\s*$/ | end | end | end | end | | sets.values.each { | a | a.uniq! } | | puts sets.keys.map { | k | '%8s ' % k }.join('|') | | rows = sets.values.map { | a | a.size }.max | | (1..rows).zip(*sets.values) do | row | | row.shift | puts row.map { | v | if v then '%8s ' % v else ' '*9 end }.join('|') | end `---- ,----[ output ] | GAMMA | OMEGA | GREEK | BETA | ALPHA | EPSILON | 3 | 2 | 8 | 0 | 1 | 7 | 6 | 5 | 11 | 15 | 4 | 12 | | 9 | | | | 10 | | 13 | | | | `---- If you don't understand the code, please ask. mfg, simon .... l