I think this is best asked using an example:
use strict; use warnings; use 5.010; use Storable qw(nstore retrieve); local $Storable::Deparse = 1; local $Storable::Eval = 1; sub sub_generator { my ($x) = @_; return sub { my ($y) = @_; return $x + $y; }; } my $sub = sub_generator(1000); say $sub->(1);
When I reset /tmp/sub.store , I see:
$VAR1 = sub { package Storable; use warnings; use strict 'refs'; my($y) = @_; return $x + $y; }
But $x never defined in this subclause. I would expect that the sub-generation expressed by sub_generator will replace $x with its actual value after generation. How do i solve this?
Please note that this question applies to this one .
function closures serialization perl store
David b
source share