Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Retriving BerkeleyDB Data

by roboticus (Chancellor)
on Aug 02, 2014 at 01:21 UTC ( [id://1095987]=note: print w/replies, xml ) Need Help??


in reply to Retriving BerkeleyDB Data

hawk2379:

It sounds like you'll just need to use the unpack function (perldoc -f unpack) to pull the byte string apart into the fields you want. I'd guess it would be something like:

my ($datetime, $open, $high, $low, $close, $volume, $interest) = unpack "A14f5Q", $h{$key};

Note: Totally untested, but I think that if you play around with unpack you'll be able to pull it apart. (You'll want to check perldoc -f pack and perldoc perlpacktut as well.)

Update: changed variable names.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Retriving BerkeleyDB Data
by hawk2379 (Novice) on Aug 02, 2014 at 02:40 UTC
    I was able to write up a rough script based on your recommendations. And it works!
    #!/usr/bin/perl use BerkeleyDB; print "start\n"; my $filename = '/home/user/Perl/AA'; #unlink $filename ; my %h ; my $dbh = tie %h, 'BerkeleyDB::Btree', -Filename => $filename, -Flags => DB_CREATE or die "Cannot open $filename $! $BerkeleyDB::Error" ; foreach $key (keys %h) { my ($open, $high, $low, $close, $volume, $interest) = unpack "dddddl", $h{$key}; print "$key: $open,$high,$low,$close,$volume,$interest\n"; # print "$h{$key}\n"; } untie %h; print "end\n";
    Thank You for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-25 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found