Experiments with PERL and BerkeleyDB
authorHarvie <tomas@mudrunka.cz>
Thu, 5 May 2011 15:55:45 +0000 (17:55 +0200)
committerHarvie <tomas@mudrunka.cz>
Thu, 5 May 2011 15:56:06 +0000 (17:56 +0200)
perl/db_file/.gitignore [new file with mode: 0644]
perl/db_file/db.pl [new file with mode: 0755]

diff --git a/perl/db_file/.gitignore b/perl/db_file/.gitignore
new file mode 100644 (file)
index 0000000..98e6ef6
--- /dev/null
@@ -0,0 +1 @@
+*.db
diff --git a/perl/db_file/db.pl b/perl/db_file/db.pl
new file mode 100755 (executable)
index 0000000..7460aa7
--- /dev/null
@@ -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;
This page took 0.110695 seconds and 4 git commands to generate.