Tuesday, September 3, 2013

Create cdb file using perl

To create cdb file in perl is quite easy when you have the hash ready.

See example below.

use strict;

use CDB_File;

my %t = (
            'a' =>'apple', 
            'b' => 'banana',

CDB_File::create %t, "<cdb file name>", "<temporary file name>";

If you have the key-value pairs in a file, you can parse through it and insert into the cdb by getting the hash ready, or by the pairs.

Say your data file contain this.


Perl code for getting this flat file data into cdb :

use strict;

use CDB_File;
my $cdb = new CDB_File("<cdb file name>", "<temporary file name>");

open (DATA, "<data file name>");

while (<DATA>) {
    my @data = split /,/;


1 comment:

  1. thanks a lot. I was looking for a simple example.