develooper Front page | perl.perl5.porters | Postings from March 2006

Storable and Closures

Thread Next
From:
David Wheeler
Date:
March 23, 2006 12:23
Subject:
Storable and Closures
Message ID:
68CC3D3E-E833-49DA-B9D5-4D2E7249855A@kineticode.com
P5Pers,

Quick question regarding Storable's support for serializing and  
deserializing code references: Given this script:

   #!/usr/bin/perl -w

   use Storable qw(freeze thaw);

   $Storable::Deparse = $Storable::Deparse || 1;
   $Storable::Eval    = $Storable::Eval || 1;

   my $var = 1;
   my $code = sub { $var };

   print $code->(), $/;
   $code = thaw(freeze($code));
   print $code->(), $/;

The output is:

   1
   Use of uninitialized value in print at /Users/david/bin/try line 11.

So the question is: How can the closure properly refer to $var when  
it's deserialized? Is there any way to properly support closures via  
Storable freeze/thaw?

Thanks!

David


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About