P
Paul
Hi there. I know I've done something similar to this before but I
seem to be stumped at the moment and thought I would ask for help.
I have a temporary Hash array that holds information in different
elements that need to be combined to produce single line outputs.
Here's some detail:
tmp_hash =
[["foo:1", "123"],
["foo:2", "abc"],
["bar:1", "456"],
["bar:2", "xyz"]]
Desired Output:
---
"foo" "123" "abc"
"bar" "456" "xyz"
---
Sample code:
---
content_alpha = ''
content_num = ''
tmp_hash.sort.each do |key, value|
(name, num) = key.split(':')
#
content_alpha = value if ( num == '1' )
content_num = value if ( num == '2' )
#
print name + "\t" + content_num + "\t" + content_alpha
end
---
I know the above doesn't produce the desired output but I haven't been
able to crack it yet. (I've tried several different solutions but am
still new to Ruby and scripting in general.) I was hoping someone
might be able to provide me with some new suggestions to try.
seem to be stumped at the moment and thought I would ask for help.
I have a temporary Hash array that holds information in different
elements that need to be combined to produce single line outputs.
Here's some detail:
tmp_hash =
[["foo:1", "123"],
["foo:2", "abc"],
["bar:1", "456"],
["bar:2", "xyz"]]
Desired Output:
---
"foo" "123" "abc"
"bar" "456" "xyz"
---
Sample code:
---
content_alpha = ''
content_num = ''
tmp_hash.sort.each do |key, value|
(name, num) = key.split(':')
#
content_alpha = value if ( num == '1' )
content_num = value if ( num == '2' )
#
print name + "\t" + content_num + "\t" + content_alpha
end
---
I know the above doesn't produce the desired output but I haven't been
able to crack it yet. (I've tried several different solutions but am
still new to Ruby and scripting in general.) I was hoping someone
might be able to provide me with some new suggestions to try.