Gerry Hickman:
# > One possibility is DBM files.  DBMs are something like 
# on-disk hashes. 
# > Perl comes with one of the formats, SDBM, on Windows.  It looks like
# > this:
# >         dbmopen %data, 'databases\trek', 0666 or die "Can't 
# open trek: 
# > $!";
# >         #Manipulate %data here
# >         dbmclose %data;
# 
# >         use Storable qw(freeze thaw);
# 
# 
# This looks good, but Storable appears to be an add-on. I 
# downloaded the 2.04 gz, but I don't know if I need to be a 
# server admin to install it on Cobalt? Can I drop it into my 
# own web space and use it from there? It says you have to run 
# a MakeFile.

Apparently it isn't in the core in 5.6.  Unfortunately, I just realized
it's not a pure Perl module, so you can't just copy it up there.  :^(
Another possibility is Data::Dumper.  You use it like this:

        use Data::Dumper 'Dumper;\";

        #build up some data structure in %hash
        ...
        
        #freeze %hash into $hash
        $hash=fixdumper(\%hash);
        
        #restore %hash from $hash
        %hash=eval $hash;

        #a wrapper around Data::Dumper

        sub fixdumper {
                my @ret;
                
                for(@_) {
                        my $ret=Dumper([$_]);
                        $ret =~ s/^\$VAR\d+=//;
                        push $ret;
                }
                
                return @ret;
        }

Note that instead of using some sort of thaw(), you simply eval() a
Data::Dumper string.  If you print the string, it's actually valid Perl
code!  (The wrapper sub is necessary because it likes to write the code
so that the data structure is set to $VAR1.)

D::D is in the core in 5.6 and maybe earlier.  If it's not installed on
the server, you should be able to just copy the module up, delete all
references to XSLoader, and watch it go.

# I assume the reason you can't put references into on-disk 
# hashes is because they're merely memory locations and will 
# have changed next time you read the hash back into memory?

That's most of it.  The other part is that if you do code like this:

        $db{foo}=$ref;
        $ref=something_else();
        $ref=$db{foo};

Not only is the thing you got back a string instead of a reference, but
the object you wanted it to point to may have been deleted.  Perl
automagically keeps track of what currently has a reference pointing to
it and what doesn't, so when all the references to something disappear,
it's deleted.  

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

He who fights and runs away wasted valuable running time with the
fighting.

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to