Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:20:23+00:00 2026-06-14T18:20:23+00:00

I remember having problem with DBI method selectrow_array . When i wasn’t tidy enough

  • 0

I remember having problem with DBI method selectrow_array. When i wasn’t tidy enough i got back from it not the value of the column i asked, but count of columns (or something unwanted, i can’t recall exactly). Now i try to refactor some code and i want to make sure in every possible place, that i get back only expected value. So i try to avoid surprises and find out which the bad behaviour was. From DBI docs i read that this may be really be problematic situation:

If called in a scalar context for a statement handle that has more
than one column, it is undefined whether the driver will return the
value of the first column or the last. So don’t do that. Also, in a
scalar context, an “undef” is returned if there are no more rows or if
an error occurred. That “undef” can’t be distinguished from an “undef”
returned because the first field value was NULL. For these reasons
you should exercise some caution if you use “selectrow_array” in a
scalar context, or just don’t do that.

Still i can’t force selectrow_array to return anything but value of the col1 (that’s it what i am expecting)

my $query = 'SELECT col1, col2, col3 FROM table WHERE id = 112233';

my ( $c ) = ( $dbh->selectrow_array( $query ) );
my $x = ask_from_db();
my $y = $dbh->selectrow_array( $query );
my $z = ( $dbh->selectrow_array( $query ) );
my @A = $dbh->selectrow_array( $query );

say "C: $c"; # C: col1
say "X: $x"; # X: col1
say "Y: $y"; # Y: col1
say "Z: $z"; # Z: col1
say "A: @A"; # A: col1 col2 col3

sub ask_from_db {
  return $dbh->selectrow_array( $query );
}

Every way i ask above, gives me fine result. How should i run the query to get wrong result?

wrong result != col1 value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:20:25+00:00Added an answer on June 14, 2026 at 6:20 pm

    The difference in outcome will be based on the implementation of the driver.

    wantarray ? @row : $row[0]
    

    vs

    wantarray ? @row : $row[-1]
    

    You’d use to use a different driver to get a different outcome. That said, I imagine you’ll have a hard time finding a driver that doesn’t return the first.

    If you want to be sure to get the first, use:

    ( $dbh->selectrow_array( $query ) )[0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems removing index.php from codeigniter-2. I remember using the same code
I remember from past having a utility that would allow to leak various system
I'm having a problem. I'm trying to do a query... I remember that in
Why don't people use CFLOGIN? I remember having problem with it with CF7 some
I remember having this problem once before but I dont' know which project it
I'm having a real problem with retrieving the value of a radio button using
I'm having a particularly interesting problem. Perhaps my don't remember the last time I
I remember having a command line tool on an older Mac OS X version
I am having difficulties to remember whether in c++ a local (non static, and
I'm not sure if this is a simulator issue, but I don't remeber having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.