Below is my code (don't worry there's a USUW at the top of the module)
I'm testing if an array ref is readonly, and if that is the case then I'm copying it into another array ref. The tests show that the array is not read-only, yet when it runs, it fails with that error. ( For those of you not familiar with me or Smart::Comments
--those ###
are Smart::Comments
.)
### readonly( $arg_ref ) : readonly( $arg_ref )
### readonly( @$arg_ref ) : readonly( @$arg_ref )
my @ro = map { readonly( $_ ) } @$arg_ref;
### @ro
if ( readonly $arg_ref ) {
$arg_ref = [ @$arg_ref ];
}
return map { my $val = shift @$arg_ref;
$_ => $val
} @_
;
This is the output I get:
### readonly( $arg_ref ) : 0
### readonly( @$arg_ref ) : 0
### @ro: [
### 0,
### 0,
### 0,
### 0,
### 0
### ]
But here's the error:
Modification of a read-only value attempted at ....pm line 247.
(247 is:
return map { my $val = shift @$arg_ref;
)
Does anybody have any familiarity with this issue? We're running Perl 5.8.7. Any idea on how to address it?
If the reference from DBI::fetchrow_arrayref
is coming back read-only, attempting to overwrite it won't help: the reference is read-only, not the thingie (i.e., the array with column values).
Make your own copy right at the source if you need destructive updates, e.g.,
my $arg_ref = [ $sth->fetchrow_array ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With