Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Readonly problems ( Scalar::Readonly::readonly )

by Anonymous Monk
on Dec 17, 2013 at 01:35 UTC ( #1067406=note: print w/replies, xml ) Need Help??

in reply to Re: Readonly problems (Devel::Peek, Scalar::Util::readonly bug)
in thread Readonly problems

Just what is 'readonly' in Perl and Perl 6?
Readonly variable
Module Readonly
What is the difference between the constant construct in Perl and the Readonly construct in Perl?
Reliability of SvREADONLY

Faster way to readonly are Attribute::Constant, Data::Lock, Scalar::Readonly,

use Scalar::Readonly qw/ readonly_on /; use Devel::Peek qw/ Dump /; my $f=66; readonly_on($f); Dump($f); __END__ SV = IV(0x99ba38) at 0x99ba3c REFCNT = 1 FLAGS = (PADMY,IOK,READONLY,pIOK) IV = 66

Scalar::Readonly::readonly also simply checks for SvREADONLY flag, and no others (no FAKE), so it'll be a false positive on HASH keys

Replies are listed 'Best First'.
Re^3: Readonly problems ( Scalar::Readonly::readonly )
by runrig (Abbot) on Dec 17, 2013 at 01:47 UTC
    Thanks, I don't really want to use readonly() though, I was just tracking down a bug involving DBI/DBD::Oracle. I tracked it down to code that went something like:
    my $data = {}; my $sth = $dbh->prepare($sql); $sth->bind_param_inout(':foo' => \$data->{foo}, 10); while ( my ($k, $v) = each %hash ) { $data->{foo} = $k; $sth->execute(); }
    And I got a 'modification of readonly value' error on the execute. Workaround is to modify the 'readonly' value before the execute with something like:
    $k .= '';
    Update: And for now, that whole thing needs a reset every few iterations, as execute() leaks memory with inout parameters.

    Update2: And the previously mentioned 'leak' has been fixed in the latest release.

      Would the following also work?
      $data->{foo} = "$k";
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        $data->{foo} = "$k";
        Yes, thanks, that does work. And is one of the few otherwise "useless use of quotes" that is not actually "useless" :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067406]
and one hand claps...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-04-25 15:24 GMT
Find Nodes?
    Voting Booth?