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-lineeyefacebookfolderfullheartglobegmailgooglegroupsimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1outlookpersonJoin Group on CardStartprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

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

From: user 1.
Sent on: Tuesday, March 9, 2010 7:36 PM
my bad.. ?I am parsing the buffer; not the brand new hash table: below is the same?code:

This my output_buffer that needs to be parsed and presented in a 3D Hash.
groupid fnam lname bday
1 abc xyz jan1
?????????def lmn feb1
2 amy morgan may1
?????????nick cary may6
Here is a sample code..
test =
test[port] =
mybuffer.each { |line|
????groupid <- 1
????fname <- 'abc'
????lname <- 'xyz'
????bday <- 'jan1'
????test = {groupid=>{fnam=>{"lname"=>lname, "bday"=>bday}}}
puts " FINAL HASH-- #{test} "
--------> When I print the final hash; I get only the last line [ nick cary may6]

On Tue, Mar 9, 2010 at 7:28 PM, Paul <[address removed]> wrote:
On Tue, Mar 9, 2010 at 6:53 PM, Swarna <[address removed]> wrote:
Here is a sample code..?

myhash = {
my_buffer,each |line|
# use the parser to get the groupid, fname, 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".?

The last line of your each() block, you are assigning a brand new Hash instance to the variable "myhash". ?I think you want that last line there to be:

myhash[groupid] = {fnam => { "lname" => lname, "bday" => bday}}


Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Paul ([address removed]) from Silicon Valley Ruby Meetup.
To learn more about Paul, 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

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy