I have a bit of weirdness going on with selectrow_array(). Example:

#!/usr/bin/perl use strict; use warnings; use v5.14; use DBI; my $dbh = DBI->connect('dbi:Pg:dbname=$dbname', '$user', '$pass', { AutoCommit => 0 } ); my ($text, $lang, $author) = $dbh->selectrow_array( q[ select( text_element, resource.language, display_name) from resource join users on ( created_by = users.id +) where short_id = '12345';] ); say $text; say $lang; say $author;

(Database name, user, and password replaced with placeholders for posting. No other changes.) Result:

("text_element_contents",eng,"Daniel Staal") Use of uninitialized value $lang in say at perl_db_test.pl line 22. Use of uninitialized value $author in say at perl_db_test.pl line 23.

So, instead of getting an array back, or even an array reference, I'm getting the entire result set as a string, which looks like an array. Any ideas what's going on here? (Note: it does the same with selectrow_arrayref() or selectrow_hashref(), except that the string is wrapped in an array/hash ref.)

(I have trimmed text_element_contents here as the actual contents are several kilobytes of text, but I get the same result with it left out entirely.)

Edit: Solved it! Weirdness... If you take out the parenthesis in the SQL statement (lines 13 and 16), it works. Now, why couldn't I have figured that out in the hour I've been beating my head against this before I posted on Perlmonks...


In reply to DBI weirdness: Arrays as strings. by DStaal

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.