SteveAtMTV
MIS
I am trying to create an array of references to arrays.
When I run the code below, it shows the correct data being pushed onto the array, but when I print it out at the end, every value is "3".
Any ideas?
Thanks,
Steve
for ($i=0; $i < @key_columns; $i++) {
if ($i == 0) {
$where = " where $key_columns[$i] = ?";
} else {
$where .= " and $key_columns[$i] = ?";
}
}
$sql_template = "select $key from $table $where";
$sth = $dbh->prepare($sql_template);
print "Prepared SQL is $sql_template\n";
$cnt = 0;
for $row (@$rows) {
$cnt++;
print "$cnt: @$row\r";
$got_row = 0;
print "Calling execute on @$row\n";
$sth->execute(@$row);
$primary_keys = $sth->fetchall_arrayref;
$rows_retrieved = int(@$primary_keys);
print "Got back $rows_retrieved\n";
$cnt += $rows_retrieved;
$got_row = 1 if @$primary_keys > 0;
for $primary_key (@$primary_keys) {
print "pushing @$primary_key\n"; # This data prints out correctly
push @new_keys, [ @$primary_key ];
# push @new_keys, $primary_key; - I also tried it like this, same result
}
# If we can't match the key from the key table with a row in the original table (probably due
# to corruption), push that key into the list of primary keys, anyway; we can try matching
# against the backup tables later...
if (! $got_row && $keys_same) {
push @new_keys, $row;
}
}
for $primary_key (@new_keys) { # This prints out wrong
print "key: " . @$primary_key . " $primary_key \n";
}
When I run the code below, it shows the correct data being pushed onto the array, but when I print it out at the end, every value is "3".
Any ideas?
Thanks,
Steve
for ($i=0; $i < @key_columns; $i++) {
if ($i == 0) {
$where = " where $key_columns[$i] = ?";
} else {
$where .= " and $key_columns[$i] = ?";
}
}
$sql_template = "select $key from $table $where";
$sth = $dbh->prepare($sql_template);
print "Prepared SQL is $sql_template\n";
$cnt = 0;
for $row (@$rows) {
$cnt++;
print "$cnt: @$row\r";
$got_row = 0;
print "Calling execute on @$row\n";
$sth->execute(@$row);
$primary_keys = $sth->fetchall_arrayref;
$rows_retrieved = int(@$primary_keys);
print "Got back $rows_retrieved\n";
$cnt += $rows_retrieved;
$got_row = 1 if @$primary_keys > 0;
for $primary_key (@$primary_keys) {
print "pushing @$primary_key\n"; # This data prints out correctly
push @new_keys, [ @$primary_key ];
# push @new_keys, $primary_key; - I also tried it like this, same result
}
# If we can't match the key from the key table with a row in the original table (probably due
# to corruption), push that key into the list of primary keys, anyway; we can try matching
# against the backup tables later...
if (! $got_row && $keys_same) {
push @new_keys, $row;
}
}
for $primary_key (@new_keys) { # This prints out wrong
print "key: " . @$primary_key . " $primary_key \n";
}