On Jan 19, 2007, at 12:55 PM, Richard Jones wrote:

while ( my $ref = $sth->fetchrow_arrayref() ) { # $ref is arrayref
  push @$ref, 1; # line xx
}

dies with 'Modification of read-only value attempted at .. line xx'

I can't see the difference here between the two $ref arrayrefs, but Perl obviously can. Unfortunately 'use diagnostics' didn't help as I think I must be missing something obvious.

Yes, that reference has a flag READONLY turned on, this is a dump of an example I ran to figure this out (attached below):

SV = RV(0x1823abc) at 0x1856984
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x1856894
  SV = PVAV(0x185848c) at 0x1856894
    REFCNT = 2
    FLAGS = (READONLY)               <-- look here
    IV = 0
    NV = 0
    ARRAY = 0x4d80b0
    FILL = 0
    MAX = 3
    ARYLEN = 0x0
    FLAGS = (REAL)
    Elt No. 0
    SV = NV(0x1813c00) at 0x1856978
      REFCNT = 1
      FLAGS = (NOK,pNOK)
      NV = 1

There are several lines in

  http://search.cpan.org/src/TIMB/DBI-1.53/DBI.xs

with this code:

  SvREADONLY_on(av);

So the answer is that you get a regular arrayref with that flag turned on by hand from XS code. That's why it is read-only.

-- fxn

use DBI;

use strict;
use warnings;

use Devel::Peek;

my $dbh = DBI->connect("dbi:SQLite:dbname=foo.db");
$dbh->do("drop table if exists foos");
$dbh->do("create table foos (id integer)");
$dbh->do("insert into foos (id) values (1)");

my $sth = $dbh->prepare("select id from foos");
$sth->execute;
Dump $sth->fetchrow_arrayref;


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to