Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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\Storable.pm (autosplit into blib\li +b\auto\Storable\_store.al) line 264, <DATA> line 1, at C:\Scripts\sto +re7.pl line 48
Any help please? Thanks in advance

Blackadder

Comment on Storing complex data structures using Storable
Select or Download Code
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: perldoc.perl.org 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-07-01 23:30 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 (25 votes), past polls