ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
changing hash key
by Tim Wolak other posts by this author
May 7 2008 6:04AM messages near this date
Help with net-ssh 2.0 | changing hash key
I am working with a script to record accounts and their balances.  I
need to check the key in a hash and if the account number is already
there just add the blanace to the value. So far this is what I have and
its not quite doing what I need.  Is my test not right?  I get all the
account numbers and their balances instead of a list with the accounts
and balances without the duplicate account numbers.

Thanks,
Tim

  sktylist = Hash.new("")
              if sktylist.has_key?('@acctnum')
                sktylist.merge!('@acctnum' =>  'value')
 else
                sktylist[@acctnum] = [value]
              end
              sktylist.each { |key, value| puts "#{key} equals #{value}"
}
-- 
Posted via http://www.ruby-forum.com/.
Thread:
Tim Wolak
Tim Wolak
Austin Ziegler
Tim Wolak
Todd Benson
Tim Wolak
7stud --
Adam Shelly
Todd Benson
Todd Benson
Todd Benson
Damjan Rems
Sebastian Hungerecker
Sandro Paganotti
Tim Wolak
Robert Dober

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved