develooper Front page | perl.perl5.porters | Postings from November 2003

Subroutine reference bug in Storable

Thread Next
From:
Andrew Sterling Hanenkamp
Date:
November 14, 2003 07:40
Subject:
Subroutine reference bug in Storable
Message ID:
3FB4F729.8070206@hanenkamp.com
I was writing some code that dinked around with Storable's deparse/eval 
and I started having problems with some CODE refs turning into SCALAR 
refs in a hash of hashes.  I don't know what the problem is, but I can 
recreate the problem with this little snippet:

use Storable qw(freeze thaw);
use Data::Dumper;

$Data::Dumper::Deparse = 1;
$Storable::Deparse     = 1;
$Storable::Eval        = 1;

push @$data, { -foo => sub { "hey foo" }, };
push @$data, { -foo => $data->[0]{-foo}, };

print Dumper($data);
print Dumper(thaw(freeze($data)));

This (on my system using Storable 2.08 and Perl 5.8.0) results in this 
output:

$VAR1 = [
          {
            '-foo' => sub {
                            'hey foo';
                        }
          },
          {
            '-foo' => $VAR1->[0]{'-foo'}
          }
        ];
$VAR1 = [
          {
            '-foo' => sub {
                            package Storable;
                            'hey foo';
                        }
          },
          {
            '-foo' => \'{
    \'hey foo\';
}'
          }
        ];

Note that the second -foo is a reference to the string "{ 'hey foo' }" 
rather than a CODE ref.  I think I should also mention that when I 
originally encountered this bug, I had multiple keys in each hash and 
the second CODE ref that was having the problem would actually pick up a 
reference to the value of a entirely different key with a scalar value.

If this bug has been fixed by 5.8.1 or 5.8.2, I apologize, but I haven't 
moved to the latest version yet.

Cheers,
Sterling

-- 
<>< ><> <>< ><> <>< ><> <>< ><> <>< ><> <>< ><> <>< ><> <>< ><> <>< ><>
  Andrew Sterling Hanenkamp
  http://Andrew.Sterling.Hanenkamp.com/
  sterling@hanenkamp.com / sterling@cis.ksu.edu

  Keep me informed on the behaviour of this kernel..  As the
  "BugFree(tm)" series didn't turn out too well, I'm starting a new
  series called the "ItWorksForMe(tm)" series, of which this new 
  kernel is yet another shining example.
                       -- Linus, in the announcement for 1.3.29
	



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