Jan Eden wrote:
>
> I want to store some complex data. My first solution made use of Storable, which
> worked just fine. Now I learned that neither Storable nor MLDBM are available on
> the machine I want to use the program on (and they cannot be made available).
>
> So I retreat to the core and use Data::Dumper to write a reference to my data to
> a file ("..." indicates an omitted hash of arrays of hashes):
>
> #!/usr/bin/perl -w
>
> use strict;
> use Data::Dumper;
>
> my %monate = ...
>
> open OUT, "> monate.dbm";
> print OUT Dumper(\%monate);
> close OUT;
>
> Next I try to restore the data. My first attempt is this:
>
> open IN, "monate.dbm";
> my $temp = join '', <IN>;
> my $reimport = eval $temp;
>
> Unfortunately, $reimport has the same value as $temp:
>
> $VAR1 = ...
>
> Reading the Data::Dumper doc? Good idea. I found the $Data::Dumper::Terse
> variable, which made Data::Dumper leave out the variable name $VAR1.
>
> Great, it works. But, from the perldoc
>
> >$Data::Dumper::Terse  or  $OBJ->Terse([NEWVAL]) When set,
> >Data::Dumper will emit single, non-self-referential values as
> >atoms/terms rather than statements.  This means that the $VARn names
> >will be avoided where possible, but be advised that such output may
> >not always be parseable by "eval".
>
> Hm. In my case, setting $Data::Dumper::Terse was absolutely necessary to make
> eval work the way I wanted it to. Is there another way to get the original data
> structure into a variable? In this context, I must admit that the different
> behaviour of eval's two forms (eval EXPR and eval BLOCK) is a bit mysterious for
> me.

Hi Jan.

Just

  my $reimport = do 'monate.dbm' or die $!;

will do what you want. It will work with or without 'Terse'.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to