Home > Archive > PERL Miscellaneous > June 2007 > Problem with Storable qw(store_fd fd_retrieve)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problem with Storable qw(store_fd fd_retrieve)
|
|
| J.D. Baldwin 2007-06-25, 7:10 pm |
|
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.
--
_+_ From the catapult of |If anyone disagrees with any statement I make, I
_|70|___:)=}- J.D. Baldwin |am quite prepared not only to retract it, but also
\ / baldwin@panix.com|to deny under oath that I ever made it. -T. Lehrer
***~~~~-----------------------------------------------------------------------
| |
| Martijn Lievaart 2007-06-25, 7:10 pm |
| On Mon, 25 Jun 2007 18:49:15 +0000, J.D. Baldwin wrote:
> 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
|
|
|
|
|