X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=perl%2Fdb_file%2Fdb.pl;fp=perl%2Fdb_file%2Fdb.pl;h=7460aa7842e61fb9a1115020ce30c18fb1760464;hb=2f01d7c3a85d28b78fb703c2eb5fb8f343a3c816;hp=0000000000000000000000000000000000000000;hpb=fe8cffc026ce97ad58b35b63e4ddb9536f59e3ca;p=mirrors%2FPrograms.git diff --git a/perl/db_file/db.pl b/perl/db_file/db.pl new file mode 100755 index 0000000..7460aa7 --- /dev/null +++ b/perl/db_file/db.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use BerkeleyDB; + +#my ( %h $k $v ); +tie my %h, "BerkeleyDB::Hash", -Filename => '_fruit.db', -Flags => DB_CREATE || die "Cannot open DB!\n"; +#tie my %h, "Tie::Hash::DBD", "dbi:SQLite:dbname=_sqlite.db"; + +# Add a few key/value pairs to the file +$h{"apple"} = "red"; +#$h{"banana"} = "yellow"; +$h{"orange"} = "orange"; +$h{"tomato"} = "red"; + +use JSON; +use Data::Dumper; +#$h{"test"} = to_json({"from" => "to", "lol" => "rofl"}); +print $h{"test"}."\n"; +print Dumper(from_json($h{"test"}))."\n"; + + +# Check for existence of a key +print "Banana Exists\n\n" if $h{"banana"}; + +# Delete a key/value pair. +delete $h{"apple"}; + +# print the contents of the file +while (my ($k, $v) = each %h) { print "$k -> $v\n" } + +untie %h;