addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1linklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ruby-99] Nested Hashes/Hash of Hashes in Ruby

From: Pavan
Sent on: Tuesday, March 9, 2010 7:29 PM
Hi,
Try

myhash = {}
my_buffer.each do |line|
??myhash[line.split[0]] = { line.split[1] => {line.split[2] => line.split[3]}}
end

Best,
Pavan

On Tue, Mar 9, 2010 at 7:02 PM, Swarna <[address removed]> wrote:

Thanks Alson. I have created the public gist. You can please access that:?http://gist.github.com/327468
Appreciate your help.


On Tue, Mar 9, 2010 at 6:55 PM, Alson Kemp <[address removed]> wrote:
? You might paste that somewhere and then post the paste so that the formatting is preserved.
? http://gist.github.com/

? - Alson


On Tue, Mar 9, 2010 at 6:53 PM, Swarna <[address removed]> wrote:
Greetings!


I have got a question regarding the Hash table in ruby on rails.
I am trying to create a 3-D hashes (hash of hashes) and loop each line of mybuffer to parse the data and dump into the hash of hashes.

For say, here is my sample data:

MY BUFFER:::
groupid fnam lname bday?
1 abc xyz jan1
def lmn feb1
2 amy morgan may1
nick cary may6


Here is a sample code..?

myhash = Hash.new {
my_buffer,each |line|
# use the parser to get the groupid, fname, lname bday
groupid?
fnam
lname
bday
myhash = {groupid=>{fnam=>{"lname"=>lname, "bday"=>bday}}}
}

Now the problem I am seeing is when i print "myhash" at the end of the function, it just prints only the last line of "mybuffer".?

How can I store all the parsed information in a 3-D Hash table?

Any input is highly appreciated.
Thanks in advance,
Swarna.




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Swarna ([address removed]) from Silicon Valley Ruby Meetup.
To learn more about Swarna, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]



--
Alson Kemp
[ m: [masked] ]
[ e: [address removed] ]
[ Skype: alsonkemp ]
[ gTalk, Jabber: [address removed] ]






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Swarna ([address removed]) from Silicon Valley Ruby Meetup.
To learn more about Swarna, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

Sign up

Meetup members, Log in