in reply to Re^2: Perl data notation
in thread Perl data notation

I believe Storable will handle subrefs, but the eval problem doesn't go away. Storable does provide a way for the user to get between the input and the eval though. And of course Storable's frozen output is anything but legible.


Dave

Replies are listed 'Best First'.
Re^4: Perl data notation
by kennethk (Abbot) on Jul 16, 2014 at 00:18 UTC

    For the truly motivated, B::Deparse can serialize into a legible format.

    use strict; use B::Deparse; my $deparse = B::Deparse->new(); my $func = sub { my %hash = @_; return $hash{a}; }; my $body = $deparse->coderef2text($func); print $body;
    You could condition the tree by crawling it and clobbering anything with reftype CODE with sprintf 'sub %s', $deparse->coderef2text($hash{key}). But this still kills closures, and plus is a terrible, terrible idea.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.