Hello I am trying to read data from a BerkeleyDB file assocciated with a program called QTstalker. With the code below, I wanted to print the key and value with the use of perl. My keys come out fine but my values are gibberish.
#!/usr/bin/perl use strict; use BerkeleyDB; my $filename = '/home/user/Perl/AA'; my %h ; tie %h, 'BerkeleyDB::Btree', -Filename => $filename, -Flags => DB_CREATE or die "Cannot open $filename $! $BerkeleyDB::Error" ; foreach $key (keys %h) { print "$key:"; print "$h{$key}\n"; }

Sample output: "20140528000000:�Q���*@+@�G�z�*@= ףp�*@Z�aA 20140529000000:��(\*@)\�(+@�p= ף*@)\�(+@o�\A 20140904000000:)\�(*@R���Q*@)\��)@*@��ʇA"

Some info I gathered from QTstalker's SourceForge forums: "The btree structure is simple enough: Each chart has it's own file somewhere in .qtstalker/data1/data, each entry in the file is a single bar of data: The keys are strings in this format: "yyyymmddHHMMSS" (eg. "20080128013000", self-explanatory) The value behind each key are 48 bytes where the first 40 bytes are five doubles representing (open,high,low,close,volume) of the bar. Last 8 bytes is a long integer representing open interest."

Ultimately, I want read the key/value pairs in human form(possibly export to an excel file) and also insert key/values that the database can store for QTstalker. If someone is kind enough to explain what I am doing wrong and decode what Im looking at, I would greatly appreciate it.


In reply to Retriving BerkeleyDB Data by hawk2379

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.