... because they should at least warn about LVALUEs not being handled correctly ...

Now hold on for a second:

Warn? Yes a warning would have been nice. Not handled correctly? No.

Documentation of Storage promises that Storage will work for SCALAR, ARRAY, HASH or REF objects:

... persistence to your Perl data structures containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be conveniently stored to disk and retrieved at a later time.

There is no promise that Storage will handle lvalue's and it doesn't, so one may actually reason it is functioning correctly.

The example script below first shows the effect of storing the lvalue in an array and changing it to undef outside of the array. After that it shows that the same behavior cannot be observed after using the Storage. The lvalue is invalidated and becomes undef. Same behavior can be observed when the lvalue is inside a hash, also the correct behavior if you ask me. I do believe a warning would have been nice though:

use strict ; use warnings ; use Storable qw( freeze thaw ) ; use Data::Dumper ; my $abc = "abc" ; my @ar = ( \( substr( $abc, 0 ) ) ) ; print "ar_0 = ${$ar[0]}\n" ; my $def = "def" ; my @ar2 = ( \( substr( $def, 0 ) ) ) ; $def = undef ; print "ar2_0 = ${$ar2[0]}\n" ; $def = 'def' ; print "ar2_0 = ${$ar2[0]}\n" ; my $serialized1 = freeze \$abc ; my $serialized2 = freeze \substr $def, 0 ; $abc = 'ghi' ; $def = 'jkl' ; $abc = ${ thaw( $serialized1 ) } ; $def = ${ thaw( $serialized2 ) } ; print "thaw abc = $abc\n" ; print "thaw def = $def\n" ; my $xyz = "xyz" ; my %xyz = ( _xyz => \substr $xyz, 0 ) ; my $ser_xyz = freeze \%xyz ; $xyz = "uvw" ; my %copyxyz = %{ thaw( $ser_xyz ) } ; print Dumper( \%copyxyz ) ; __END__ ar_0 = abc Use of uninitialized value in concatenation (.) or string at test2.pl +line 13. ar2_0 = ar2_0 = def thaw abc = abc Use of uninitialized value $def in concatenation (.) or string at test +2.pl line 25. thaw def = $VAR1 = { '_xyz' => \undef };

In reply to Re^2: Subtle(?) issue(?) with lvalues and serialization by Veltro
in thread Subtle(?) issue(?) with lvalues and serialization by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.