Fellow monasterians,
I'm returning an array (yes, I know it's really a list) from an subroutine by reference. So far, so good. However, I'm not able to INSERT those returned dereferenced values into my database. This first bit of code returned the bizarre error: unknown column 'actual_value_I'm_trying_to_place' in 'field list' (which is discussed in this node). Much simplified (hope I didn't lose anything):
my $ref = &subroutine( $fee, $fie, $foo, $fum ); $sth = $dbh->prepare ( "INSERT INTO mytable VALUES(?,?,?,?)" ); $sth->execute ( @$ref[0], @$ref[1], @$ref[2], @$ref[3] ) ; sub subroutine { my @ref = @_; ... return (\@ref); }
Data::Dumper is our friend:
print Dumper(@$ref[0], @$ref[1], @$ref[2], @$ref[3]); $VAR1='aaaaaaa'; $VAR2='bbbbbbb'; $VAR3='ccccccc'; $VAR4='ddddddd';
If I hard code it, all is fine:
my @ref = qw( aaaaaaa bbbbbbb cccccccc ddddddd ); $sth->execute ( $ref[0], $ref[1], $ref[2], $ref[3] );
I even tried, unsuccessfully, re-assigning the references to a regular array (desperation):
my @array = ( @$ref[0], @$ref[1], @$ref[2], @$ref[3] ); $sth->execute ($array[0], $array[1], $array[2], $array[3]);
So, my questions: 1) is my original subroutine referenced return okay? 2) is it true that you can't INSERT derefenced values into MySQL? 3) how to I do this without just declaring a big fat global and avoiding the references? As always, thanks in advance.
In reply to Unable to INSERT dereferenced values into db by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |