package SubscriberList;
use strict;
use warnings;
use vars qw($VERSION);
$VERSION = '0.01';
use Data::Dumper;
use DB_File;
use Storable qw(freeze thaw);
sub new
{
my ($class,%args) = @_;
# get args
my $this;
$this->{filename} = $args{filename};
tie %{$this->{db}}, 'DB_File', $this->{filename};
bless $this, $class;
return $this;
}
sub DESTROY
{
my ($this) = @_;
untie %{$this->{db}};
}
sub add_subscriber
{
my ($this,%new_sub) = @_;
my $email = $new_sub{email};
delete $new_sub{email};
$this->{db}->{$email} = freeze \%new_sub;
return $this;
}
1;
####
# test.pl
use SubscriberList;
$list = new SubscriberList(filename=>'test.db');
$list->add_subscriber(
email=>'new@email.com',
first_name => 'New',
last_name => 'Subscriber',
);
$list->add_subscriber(
email=>'jar@jar.com',
first_name => 'JarJar',
last_name => 'Binks',
);
##
##
use Data::Dumper;
use DB_File;
tie %hash, 'DB_File', 'test.db';
print Dumper(\%hash);
############
Ouput
$VAR1 = {};