Ruby dbm writer - write a key/value to a dbm file

require 'time'
require 'sdbm'
 
if (ARGV.size < 2) then
    puts "Need two arguments, lastname, firstname"
    exit
end
puts "#{ARGV[0]} #{ARGV[1]}"
 
SDBM.open('dbmFile',0666) { |dbobj|
    v = dbobj["count"]
    nextIndex = v.to_i
    lnameIndex = "lastname" + v.to_s
    fnameIndex = "firstname" + v.to_s
    dbobj[lnameIndex] = ARGV[0]
    dbobj[fnameIndex] = ARGV[1]
    nextIndex = nextIndex.succ
    puts nextIndex.to_s
    dbobj["count"] = nextIndex.to_s
}

Back to Ruby

rubydbmwriter.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