Ruby dbm usage

#!/usr/bin/ruby
#
# $Id$
#
# DBM_RB
#
 
require 'time'
require 'sdbm'
 
SDBM.open("dbmFile", 0666)  { |dbobj|
# raises exception if open error
 
# the returned sdbm-dbobj has most of the methods of a hash
    v = dbobj["key"]
    puts "oldValue = #{v}"
    now = Time.now
    second = now.strftime('%S')
    dbobj["key"] = "newvalue" + second
    if dbobj.has_key?("key")
    # ...
    end
    dbobj.delete("key2")
}
 
# database is open only inside the block.
SDBM.open("dbmFile",0666) { |ddobj|
    v = ddobj["key"]
    puts v.class
    puts v
    ddobj["fname"] = "madan"
    ddobj["lname"] = "nain"
}

Back to Ruby

rubydbmusage.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0