Differences

This shows you the differences between two versions of the page.

Link to this comparison view

rubydbmwriter [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== Ruby dbm writer - write a key/value to a dbm file =====
 +<code ruby>
 +
 +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
 +}
 +
 +</​code>​
 +----
 +[[rubyinfo|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