Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Does any one know if it's possible to read in or populate Data::Dumper with a file that was produced via Data::Dumper?
## Compiled by SNMP::MIB::Compiler version 0.06 ## Source: C:\MIBS/RFC-1212.mib ## Date: Fri Mar 7 16:42:52 2003 { 'tree' => undef, 'macros' => [ 'OBJECT-TYPE' ], 'traps' => undef, 'nodes' => {}, 'version' => '0.06', 'types' => { 'IndexSyntax' => { 'items' => { 'ipAddress' => { 'type' => 'IpAddress' }, 'object' => { 'type' => 'OBJECT IDENTIFIER' }, 'string' => { 'type' => 'OCTET STRING' }, 'address' => { 'type' => 'NetworkAddress' }, 'number' => { 'range' => { 'min' => '0', 'max' => 'MAX' }, 'type' => 'INTEGER' } }, 'type' => 'CHOICE' } } }
Is it possible to populate an array using the same data structure with the above data?

Replies are listed 'Best First'.
Re: Data::Dumper Retrieval?
by Elian (Parson) on Mar 10, 2003 at 15:03 UTC
    Data::Dumper returns a structure suitable for passing to eval for reconstruction. Take the data it produced and do a string eval on it. (There are instructions in the Data::Dumper documentation)
Re: Data::Dumper Retrieval?
by broquaint (Abbot) on Mar 10, 2003 at 15:18 UTC
    Given a a file containing Data::Dumper output you can just get back your data with a simple do()
    my $data = do "somefile.dump";
    Although this won't work with multiple structures in the file as it only returns the last thing evaluated.
    HTH

    _________
    broquaint

Re: Data::Dumper Retrieval?
by zby (Vicar) on Mar 10, 2003 at 15:05 UTC
    Try eval on the filecontent or do on the file.
Re: Data::Dumper Retrieval?
by Tomte (Priest) on Mar 10, 2003 at 15:05 UTC

    If I'm not mistaken, you can eval Data::Dumper output into new existence, something in the line of:

    my $hash = eval { $filecontents };

    This will fail only on code-refs, which you don't seem to have in your dumped structure.
    perldoc Data::Dumper tells you more about this.

    regards,
    tomte