package Tie::FreezeThaw; # NOTE: # This is a quick hack and has NOT been tested thoroughly! # NOTE: # You can't use the elements directly as references! # (if @xyzzy is tied, $xyzzy[1][2] won't work. # Use $foo = $xyzzy[1]; $foo->[2] instead.) use FreezeThaw qw(freeze thaw); use base 'Tie::Array'; use strict; sub TIEARRAY { bless $_[1], $_[0] } sub FETCHSIZE { scalar @{ $_[0] } } sub STORESIZE { @{ $_[0] } = $_[1] } sub EXISTS { exists $_[0]->[$_[1]] } sub DELETE { delete $_[0]->[$_[1]] } sub STORE { ($_[2] = freeze $_[2]) =~ s/([^\x20-\x7E])/sprintf "\xFF%02x", $1/ge; $_[0]->[$_[1]] = $_[2]; } sub FETCH { (my $foo = $_[0]->[$_[1]]) =~ s/\xFF(..)/chr hex $1/ge; return (thaw $foo)[0]; } 1; #### use Tie::File; use Tie::FreezeThaw; use strict; tie my @foo, 'Tie::File', 'testfile' or die $!; tie my @bar, 'Tie::FreezeThaw', \@foo; push @bar, [ qw/1..10/ ];