List folks --

I wanted to tie an array to a file and store references. I want the data available to the next session, so I need Storable, or something like it. I do this with hashes all the time, but never with an array.

What I found is that it didn't work as I expected it would. I looked a little deeper and finally added a line to make it work. This seems counterintuitive enough to warrant a note in the docs, perhaps. [Unless I'm barking up the wrong tree entirely, and should perhaps take a better route. '-) ]

Here's the script:

#!/usr/bin/perl
use DB_File;
use Storable qw/freeze thaw/;
use strict;

$DB_RECNO->{bval} = "\r";         # needed for use with storable ??

tie my @test, 'DB_File', 'test.db', O_CREAT|O_RDWR, 0666, $DB_RECNO
            or die $!;

#undef @test;

my @t = ('a'..'d');

for (1..10){
    unshift @t, (pop @t);
    push @test, (freeze [$_,@t]);
    }

for (@test){
    my $t = thaw $_;
    print $t->[0], "\n";
    }


untie @test;

__END__

Setting the value 'bval' for the DB_RECNO hash is what fixed the problem. Otherwise, apparently, the default 'bval' char shows up in the data 'freeze'd with Storable, mucking up the array when you tie to the file again.

I see the same behavior on linux as well.

Any thoughts or comments? Is there a better way to do this?

-- mike higgins

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to