I'm writing a module using DB_File. The data seems to get saved to the file 'test.db' but fetching or Data::Dumper() the file doesn't seem to dump the data. Here's what I have so far:

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;
...and here is the test script to add an entry:
# 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', );
...and here is the code that dumps the seemingly empty data file:
use Data::Dumper; use DB_File; tie %hash, 'DB_File', 'test.db'; print Dumper(\%hash); ############ Ouput $VAR1 = {};
The 'test.db' file seems to have data in it because when I run it through the command 'strings' all the values seem to be there.

Any suggestions? (besides go to bed and try agian tomorrow? ;-)

Cheers!

--
hiseldl
What time is it? It's Camel Time!


In reply to 'tie' in a module, but having trouble fetching by hiseldl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.