Problem with Storable qw(store_fd fd_retrieve)

Discussion in 'Perl Misc' started by J.D. Baldwin, Jun 25, 2007.

  1. J.D. Baldwin

    J.D. Baldwin Guest

    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
    \ / |to deny under oath that I ever made it. -T. Lehrer
    ***~~~~-----------------------------------------------------------------------
     
    J.D. Baldwin, Jun 25, 2007
    #1
    1. Advertising

  2. 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
     
    Martijn Lievaart, Jun 25, 2007
    #2
    1. Advertising

  3. J.D. Baldwin

    J.D. Baldwin Guest

    In the previous article, Martijn Lievaart <> wrote:
    > (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.


    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.
    --
    _+_ 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
    \ / |to deny under oath that I ever made it. -T. Lehrer
    ***~~~~-----------------------------------------------------------------------
     
    J.D. Baldwin, Jun 26, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Hembree
    Replies:
    0
    Views:
    1,199
    Daniel Hembree
    Jan 12, 2004
  2. Harsha
    Replies:
    1
    Views:
    579
  3. Replies:
    3
    Views:
    2,442
    Jim Gibson
    Mar 29, 2005
  4. Kenjis Kaan

    Storable module for Activestate 5.6.1??

    Kenjis Kaan, Jun 30, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    149
    Sisyphus
    Jul 1, 2003
  5. arun
    Replies:
    1
    Views:
    1,421
    Rainer Weikusat
    Mar 8, 2012
Loading...

Share This Page