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.


—Brad
"A little yeast leavens the whole dough."

In reply to Unable to INSERT dereferenced values into db by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.