Lepsi tester seriovky
[mirrors/Programs.git] / perl / db_file / db.pl
CommitLineData
2f01d7c3
H
1#!/usr/bin/env perl
2use strict;
3use warnings;
4use BerkeleyDB;
5
6#my ( %h $k $v );
7tie my %h, "BerkeleyDB::Hash", -Filename => '_fruit.db', -Flags => DB_CREATE || die "Cannot open DB!\n";
8#tie my %h, "Tie::Hash::DBD", "dbi:SQLite:dbname=_sqlite.db";
9
10# Add a few key/value pairs to the file
11$h{"apple"} = "red";
12#$h{"banana"} = "yellow";
13$h{"orange"} = "orange";
14$h{"tomato"} = "red";
15
16use JSON;
17use Data::Dumper;
18#$h{"test"} = to_json({"from" => "to", "lol" => "rofl"});
19print $h{"test"}."\n";
20print Dumper(from_json($h{"test"}))."\n";
21
22
23# Check for existence of a key
24print "Banana Exists\n\n" if $h{"banana"};
25
26# Delete a key/value pair.
27delete $h{"apple"};
28
29# print the contents of the file
30while (my ($k, $v) = each %h) { print "$k -> $v\n" }
31
32untie %h;
This page took 0.438563 seconds and 4 git commands to generate.