modification of a read-only value

IvorW heno-fijw at xemaps.com
Tue Jun 3 05:42:55 BST 2008


David Alban wrote:
> greetings,
>
> as a fan of the Readonly module, i've seen and corrected many
> situations where i get "Modification of a read-only value attempted".
> but i got one today i don't quite grok.
>
> i have a routine ql() that i use often.  apparently i first used it on
> a Readonly only just today.  i seems that Data::Dumper::Dumper() is
> doing something to offend Readonly.  in my example below, old_ql() is
> a boiled down version of my subroutine and new_ql() is the
> modification i made to get it to work with Readonly constants.  the
> program below outputs:
>
> $VAR1 = "\177";
> Modification of a read-only value attempted at
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/Data/Dumper.pm line 611
> Modification of a read-only value attempted at junk line 0
>
> Here's the test program:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use Data::Dumper;
> use Readonly;
>
> Readonly::Scalar my $c => chr hex "7f";
>
> print new_ql( $c );
> print old_ql( $c );
>
> sub new_ql {
>   my @args_copy = @_;
>
>   "@args_copy" =~ m{ [^[:print:]] }xms and $Data::Dumper::Useqq  = 1;
>   return join( ", ", map { Dumper $_; } @args_copy );
> } # new_ql
>
> sub old_ql {
>   "@_" =~ m{ [^[:print:]] }xms and $Data::Dumper::Useqq  = 1;
>   return join( ", ", map { Dumper $_; } @_ );
> } # old_ql
>
> the only difference between the old and new routines is using a copy of @_.
>   
Interesting... Looks like the tieing of $c is causing an issue with Dumper.

Applying the Swiss army sledgehammer (perl5db) exposes that
just looking at @_ to see what's in there breaks Readonly::Scalar

Here's my session:
ivor at orinoco:~$ perl -d foo.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(foo.pl:10):      Readonly::Scalar my $c => chr hex "7f";
                                                                                 

DB<1> n
main::(foo.pl:12):      print new_ql( $c );
                                                                                 

DB<1>
$VAR1 = "\177";
main::(foo.pl:13):      print old_ql( $c );
                                                                                 

DB<1> s
main::old_ql(foo.pl:23):          "@_" =~ m{ [^[:print:]] }xms and
$Data::Dumper::Useqq  = 1;
                                                                                 

DB<1> s
Readonly::Scalar::FETCH(/usr/local/share/perl/5.8.8/Readonly.pm:71):
71:         my $self = shift;
                                                                                 

DB<1> r
scalar context return from Readonly::Scalar::FETCH: "\c?"
main::old_ql(foo.pl:24):          return join( ", ", map { Dumper $_; }
@_ );
                                                                                 

DB<1> s
main::old_ql(foo.pl:24):          return join( ", ", map { Dumper $_; }
@_ );
                                                                                 

DB<1>
Data::Dumper::Dumper(/usr/lib/perl/5.8/Data/Dumper.pm:511):
511:      return Data::Dumper->Dump([@_]);
                                                                                 

DB<1>
Readonly::Scalar::FETCH(/usr/local/share/perl/5.8.8/Readonly.pm:71):
71:         my $self = shift;
                                                                                 

DB<1> x @_
0  Readonly::Scalar=SCALAR(0x841c668)
   -> Modification of a read-only value attempted at
/usr/share/perl/5.8/dumpvar.pl line 83
 at /usr/local/share/perl/5.8.8/Readonly.pm line 75
       
Readonly::Scalar::__ANON__[/usr/local/share/perl/5.8.8/Readonly.pm:76]('Readonly::Scalar=SCALAR(0x841c668)',
'\c?') called at /usr/share/perl/5.8/dumpvar.pl line 83
        dumpvar::stringify('\x{7f}', '') called at
/usr/share/perl/5.8/dumpvar.pl line 115
        dumpvar::DumpElem('\x{7f}', 6, -3) called at
/usr/share/perl/5.8/dumpvar.pl line 270
        dumpvar::unwrap('Readonly::Scalar=SCALAR(0x841c668)', 3, -2)
called at /usr/share/perl/5.8/dumpvar.pl line 127
        dumpvar::DumpElem('Readonly::Scalar=SCALAR(0x841c668)', 3, -2)
called at /usr/share/perl/5.8/dumpvar.pl line 253
        dumpvar::unwrap('ARRAY(0x85fa394)', 0, -1) called at
/usr/share/perl/5.8/dumpvar.pl line 34
        main::dumpValue('ARRAY(0x85fa394)', -1) called at
/usr/share/perl/5.8/perl5db.pl line 5576
        DB::dumpit('GLOB(0x81ecc9c)', 'ARRAY(0x85fa394)') called at
/usr/share/perl/5.8/perl5db.pl line 657
        DB::eval called at /usr/share/perl/5.8/perl5db.pl line 3410
        DB::DB called at /usr/local/share/perl/5.8.8/Readonly.pm line 71
        Readonly::Scalar::FETCH('Readonly::Scalar=SCALAR(0x841c668)')
called at /usr/lib/perl/5.8/Data/Dumper.pm line 511
        Data::Dumper::Dumper('\x{7f}') called at foo.pl line 24
        main::old_ql('\x{7f}') called at foo.pl line 13
Modification of a read-only value attempted at
/usr/share/perl/5.8/Carp.pm line 102
 at /usr/local/share/perl/5.8.8/Readonly.pm line 75
       
Readonly::Scalar::__ANON__[/usr/local/share/perl/5.8.8/Readonly.pm:76]('Readonly::Scalar=SCALAR(0x841c668)',
'\x{7f}') called at /usr/share/perl/5.8/Carp.pm line 102
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
                                                                                 

DB<<2>>                  



More information about the london.pm mailing list