Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Module to read a dumped file

by juo (Curate)
on Feb 11, 2003 at 14:36 UTC ( #234404=perlquestion: print w/ replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody know of a module that can read a dumped file and put it back into a hash structure. Below you can see an example of the code to generate a dumped file of a hash table. But I could not find a module to read the dumped file and put it back into a hash table.

open (STDOUT, ">whatever.dat"); use Dumpvalue; my $dumper = new Dumpvalue; $dumper->dumpValue(\%flexlm);

Result of the dumped file

'dataParams' => HASH(0x1ee5ef4) 'license_feature' => HASH(0x1ee5f0c) 'val' => 'geditor' 'license_server' => HASH(0x1ee5f30) 'val' => '10.210.134.126' 'licenses_used' => HASH(0x1ee5f78) 'val' => 7 'machine_names' => HASH(0x1ee5fcc) 'parmOptions' => ARRAY(0x1cd9b24) 0 'solw0328' 1 'solw0082' 2 'vasw1006' 3 'lav000021453a' 4 'tczw5216' 5 'CRKW388' 6 'vasw1005' 'total_licenses' => HASH(0x1ee5f54) 'val' => 15 'user_names' => HASH(0x1ee5fa8) 'parmOptions' => ARRAY(0x1b8442c) 0 'solwebef' 1 'solwebef' 2 'vaskhall' 3 'lvlvalor' 4 'tczrale' 5 'crkjcree' 6 'vasplund'

Comment on Module to read a dumped file
Select or Download Code
Replies are listed 'Best First'.
Re: Module to read a dumped file
by ropey (Hermit) on Feb 11, 2003 at 14:42 UTC
    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.

      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

        Once you have read it in from the file and stored in a scalar, just do
        my $ref = eval $data;
Re: Module to read a dumped file
by CountZero (Bishop) on Feb 11, 2003 at 15:19 UTC

    I always understood that you could eval the output of Data::Dumper to get the original variable structure back.

    Reading the outputfile into a scalar variable and eval-ing this scalar should to the trick.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Module to read a dumped file
by Jeppe (Monk) on Feb 11, 2003 at 16:57 UTC
    If you don't need to transfer the data between platforms, Storable is up to the job.
    $string = freeze($hashref); $hashref = thaw($string);
    Also, Data::DumpXML is worth looking into. And the good old Data::Dumper.
Re: Module to read a dumped file
by jammin (Novice) on Feb 11, 2003 at 17:32 UTC
    To read a Data::Dumped file back I just use: my $hash = do 'filename';
Re: Module to read a dumped file
by thor (Priest) on Feb 12, 2003 at 00:33 UTC
    if it's persistence you're looking for and don't care if it's readable or not, have a look at Storable

    thor

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://234404]
Approved by bronto
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2015-07-29 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls