Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

'tie' in a module, but having trouble fetching

by hiseldl (Priest)
on May 28, 2003 at 04:13 UTC ( #261205=perlquestion: print w/replies, xml ) Need Help??

hiseldl has asked for the wisdom of the Perl Monks concerning the following question:

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:
# use SubscriberList; $list = new SubscriberList(filename=>'test.db'); $list->add_subscriber( email=>'', first_name => 'New', last_name => 'Subscriber', ); $list->add_subscriber( email=>'', 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? ;-)


What time is it? It's Camel Time!

Replies are listed 'Best First'.
Re: 'tie' in a module, but having trouble fetching
by PodMaster (Abbot) on May 28, 2003 at 04:22 UTC
    What happens if you can't tie the file?
    Heard of the untie gotcha? Read perltie.

    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://261205]
Approved by djantzen
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-01-17 17:19 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (51 votes). Check out past polls.