if I have this code (using on a mysql database):
[tt]while (my $row = $sth->fetchrow_arrayref) {
foreach (@$row) { $_ = "NULL" unless defined }
my (@end) = splice(@$row, -2);
print join (", ",@$row)." - ".join(", ",@end)."\n";
}[/tt]
it will print the first row as it should, then it gives a "Modification of a read-only value attempted...." error.
Why is this? and how do I avoid it? I know I can avoid it by not using a reference, ie this works fine:
[tt]while (my @row = $sth->fetchrow_array) {
foreach (@row) { $_ = "NULL" unless defined }
my (@end) = splice(@row, -2);
print join (", ",@row)." - ".join(", ",@end)."\n";
}[/tt]
But I'm curious why the reference version gives the error. Is there any way I can do this without using the non-reference version? I know either way it's not a big deal.
thanks
[tt]while (my $row = $sth->fetchrow_arrayref) {
foreach (@$row) { $_ = "NULL" unless defined }
my (@end) = splice(@$row, -2);
print join (", ",@$row)." - ".join(", ",@end)."\n";
}[/tt]
it will print the first row as it should, then it gives a "Modification of a read-only value attempted...." error.
Why is this? and how do I avoid it? I know I can avoid it by not using a reference, ie this works fine:
[tt]while (my @row = $sth->fetchrow_array) {
foreach (@row) { $_ = "NULL" unless defined }
my (@end) = splice(@row, -2);
print join (", ",@row)." - ".join(", ",@end)."\n";
}[/tt]
But I'm curious why the reference version gives the error. Is there any way I can do this without using the non-reference version? I know either way it's not a big deal.
thanks