Problem with Storable qw(store_fd fd_retrieve)

J

J.D. Baldwin

Not sure why Storable's sister functions won't talk each other's
language. Here's a stripped down version of what I have:

#!/bin/perl

use strict;
use warnings;

use Storable qw(store_fd fd_retrieve);
use Data::Dumper;
my $uploaded_ref;

my $TRACKING_DATA_FILE='tracking.dat'; # Does not exist
my $LIST_FILE='biglist.txt'; # 64,109-line text file,
# one token per line

open my $fd, '>', $TRACKING_DATA_FILE;
open my $list_fd, '<', $LIST_FILE;

while ( <$list_fd> )
{
chomp;
$uploaded_ref->{$_} = 1;
}

store_fd($uploaded_ref, $fd);
close $fd;

open $fd, '>>', $TRACKING_DATA_FILE;
my $new_ref = fd_retrieve($fd);

my $numkeys = keys %{$new_ref};
print "Number: $numkeys\n";

This fails with

Magic number checking on storable file failed at blib/lib/Storable.pm
(autosplit into blib/lib/auto/Storable/fd_retrieve.al) line 398,
<$list_fd> line 64109, at ./init.pl line 27

Any ideas what is going on here? I have to use store_fd and
fd_retrieve because of the kind of locking my project requires.

Storable version is 2.16; Perl is 5.8.8.
 
M

Martijn Lievaart

Not sure why Storable's sister functions won't talk each other's
language. Here's a stripped down version of what I have:

(snip)

I'm not sure, but...
open $fd, '>>', $TRACKING_DATA_FILE;

You open $fd for append...
my $new_ref = fd_retrieve($fd);

.... and try to read from it.
my $numkeys = keys %{$new_ref};
print "Number: $numkeys\n";

This fails with

Magic number checking on storable file failed at
blib/lib/Storable.pm
(autosplit into blib/lib/auto/Storable/fd_retrieve.al) line 398,
<$list_fd> line 64109, at ./init.pl line 27

As there is nothing to read, the magic number check fails.

HTH,
M4
 
J

J.D. Baldwin

In the previous article said:
(snip)

I'm not sure, but...


You open $fd for append...


... and try to read from it.

Arrrgh. I had '+<' in the original and switched it to '>>' on a
desperation try. Now I'm getting a different error -- I'll try to
boil it down to the smallest postable program snippet and post again.
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top