How to read Perl DB_Files in Ruby

霸气de小男生 提交于 2019-12-11 12:55:33

问题


I'm migrating a Perl script to Ruby. The Perl script uses DB_File in DB_HASH mode. How do I read all the keys and values from such a file in Ruby?


回答1:


I finally realized that DB_HASH is a Berkeley DB file format.

I didn't have libdb for Ruby on my Ubuntu box but that was fixed with a simple apt-get

apt-get install libdb4.2-ruby1.8

Then in Ruby

require 'bdb'
db=BDB::Hash.open("test.db")
keyvalues=db.to_hash


来源:https://stackoverflow.com/questions/2214838/how-to-read-perl-db-files-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!