Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: marshalling data

by tobyink (Abbot)
on Mar 12, 2013 at 07:14 UTC ( #1022930=note: print w/ replies, xml ) Need Help??


in reply to marshalling data

If you take a look at the $marshall_data variable, it contains this line:

@data2 = @{$data1[2]};

This makes @data2 into a shallow clone of @{$data1[2]} - i.e. they are now different arrays. :-(

I can get it to work if I serialize to arrayrefs rather than arrays. (PS: it's not that much work to get it to run under strict too!)

use v5.14; use strict; # redundant! use warnings; use Data::Dumper; package main { our @data1 = qw(one won); our @data2 = qw(two too to); push @data2, \@data1; push @data1, \@data2; open my $FH, '>', \(our $marshall_data); print {$FH} Data::Dumper->Dump( [ \@data1, \@data2 ], [qw($data1 $data2)] ); close $FH; print "NO " if \@data2 != $data1[2]; print "CIRCULAR DATA STRUCTURE in package main\n"; } package Other { open my $FH, '<', \$main::marshall_data; my $string = do {local $/ = undef; <$FH>}; close $FH; our (@data1, @data2); (*data1, *data2) = do { my ($data1, $data2); # declare eval $string; ($data1, $data2); }; die "$@\n" if $@; print "NO " if \@data2 != $data1[2]; print "CIRCULAR DATA STRUCTURE in package other\n"; print \@data2, ' ', $data1[2], "\n\n"; }
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: marshalling data
Select or Download Code
Re^2: marshalling data
by BillKSmith (Chaplain) on Mar 12, 2013 at 12:30 UTC
    Your solution requires Other to know the variable names at compile time. I think the whole idea is to preserve the variable names as well as their values.
    Bill

      Why in earth would Other want to unmarshall some variables without knowing what they're called? If it didn't know what they were called, it couldn't very well make practical use of the data contained in them.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        Good point! This may be exactlly what I got wrong.
        Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-12-26 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls