Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Storing complex data structures using Storable

by blackadder (Hermit)
on Jan 27, 2010 at 18:52 UTC ( #819999=perlquestion: print w/replies, xml ) Need Help??
blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

Any reason please as why I cannot save a complex data structure ($datacenters) to the disk?

This is the snippet of script that extracts data from vmware virtual centre and uses storable to store to disk
#! c:/perl/bin/perl.exe # use strict; use Data::Dumper; use Storable qw(store retrieve freeze thaw dclone); use VMware::VILib; use VMware::VIRuntime; my $datacenter_views = Vim::find_entity_views( view_type=> 'Datace +nter'); foreach my $DataCenter (@$datacenter_views) { store(\$DataCenter, 'c:/DCDump') or die "Can't store %a in DCD +ump!\n"; } my $colref = retrieve('c:/DCDump'); die "Unable to retrieve from DCDump!\n" unless defined $colref; print Dumper $colref;
However, the error I get is this:
Can't store CODE items at blib\lib\ (autosplit into blib\li +b\auto\Storable\ line 264, <DATA> line 1, at C:\Scripts\sto line 48
Any help please? Thanks in advance


Replies are listed 'Best First'.
Re: Storing complex data structures using Storable
by kennethk (Abbot) on Jan 27, 2010 at 19:14 UTC
    The error says precisely why you cannot store the data structure - it contains a code reference (perlref). The Storable documentation explains how to store coderefs, but with the caveat that this has significant possible security implications.
Re: Storing complex data structures using Storable
by MidLifeXis (Monsignor) on Jan 27, 2010 at 19:22 UTC

    Try the suggestion at Storable's section on code references [Note: was down when I posted this. I hope I have the right reference. --MLX ].

    It is said that "only perl can parse Perl." I don't even come close until my 3rd cup of coffee. --MidLifeXis

Re: Storing complex data structures using Storable
by BioLion (Curate) on Jan 28, 2010 at 15:18 UTC

    I had a similar problem a while back and pople had some really helpful suggestions : Storable Objects. HTH.

    Just a something something...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://819999]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-12-12 15:09 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.