in reply to Module to read a dumped file

Looks like your code doesn't dump your data structure correctly. ('machine_names' => HASH(0x1ee5fcc)) will not work. Have a look at Data::Dumper, that should provide all the functionality you need.

Replies are listed 'Best First'.
Re: Re: Module to read a dumped file
by juo (Curate) on Feb 11, 2003 at 15:02 UTC

    I have checked out the Data::Dumper and indeed it allows to dump a hash table and it is slightly in a different structure then the dumpvalue does but I could not find how to read back a dumped file. Like dumpvalue it only goes in one direction.

    use Data::Dumper; open (STDOUT, ">whatever.dat"); print Dumper(%flexlm); close STDOUT;
    $VAR1 = 'dataParams'; $VAR2 = { 'license_feature' => { 'val' => 'geditor' }, 'total_licenses' => { 'val' => '15' }, 'machine_names' => { 'parmOptions' => [ 'solw0328', 'solw0082', 'vasw1006', 'lav000021453a', 'tczw5216', 'CRKW388', 'vasw1005' ] }, 'user_names' => { 'parmOptions' => [ 'solwebef', 'solwebef', 'vaskhall', 'lvlvalor', 'tczrale', 'crkjcree', 'vasplund' ] }, 'licenses_used' => { 'val' => 7 }, 'license_server' => { 'val' => '10.210.134.126' } };
      I could not find how to read back a dumped file
      Like so
      use Data::Dumper; my %hash = qw( foo one bar two baz three ); open DATA, ">whatever.dat"; print DATA Dumper(\%hash); close DATA; my %hash2 = %{ do "whatever.dat" }; print Dumper(\%hash2); __output__ $VAR1 = { 'foo' => 'one', 'baz' => 'three', 'bar' => 'two' };
      For more info see the ever-magical do() function.
      HTH

      _________
      broquaint

        That it was that simple after all. This is doing the job except for one thing. If your hashtable contains a non-referenced top level it will be removed during the input using do. See sample below

        Original hash table

        $VAR1 = 'dataParams'; $VAR2 = { 'license_feature' => { 'val' => 'geditor' }, };

        New hash table

        $VAR1 = 'license_feature'; $VAR2 = { 'val' => 'geditor' };

        So it is not exactly the same but it already helps a lot.

      Once you have read it in from the file and stored in a scalar, just do
      my $ref = eval $data;