Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

Replies are listed 'Best First'.
Re^2: marshalling data
by BillKSmith (Priest) 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.

      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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2016-10-26 13:26 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (340 votes). Check out past polls.