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

  • Home
  • SEARCH
  • 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 6166913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:25:19+00:00 2026-05-23T22:25:19+00:00

How do I grab another column from a fetchrow_hashref? For example, my original sub

  • 0

How do I grab another column from a fetchrow_hashref?

For example, my original sub routine returned one value.

 sub get_val
    {
      undef $/;
      open (my $FH, "< tst.sql") or die "error can't open this file $!";
      my $sth= $dbh->prepare(<$FH>) ||
          die ("Cannot connect to the database: ".$DBI::errstr."\n");
      $sth->execute;
      close $FH;
      my $row = $sth->fetchrow_hashref;
      $sth->finish;
      return $row->{COL1};
      print $row;
    }

I altered my sql, so now I’m getting 2 values in return and want to fetch COL2

COL1     COL2
------   -------
1        A

Here is where I call by get_val:

my $dbh = DBI->connect(
      $abc{oracle_dbi_connect},
      $abc{usr},
      $abc{pw},
      {AutoCommit => 0,RaiseError => 0, PrintError => 0}) || die ("Cannot connect to the database: ".$DBI::errstr."\n");
my $val = get_val();
$dbh->disconnect();

I probably would then want to assign COL2 results to a new $val2?

  • 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-05-23T22:25:20+00:00Added an answer on May 23, 2026 at 10:25 pm

    I’m sure getting COL2 is as simple as using $row->{COL2} instead of $row->{COL1} (as you had in your code). So, make your get_val function return two values:

    return @$row{'COL1', 'COL2'};
    

    and in the calling function:

    my ($val, $val2) = get_val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to grab a div from another website using JS. I
I've got a PHP application which needs to grab the contents from another web
Let's say I just want to use PHP include to grab HTML from another
I need to copy some data from one table to another but I need
I'm looking for information on how/if you can grab information from another app in
I need to join another table to my query, and grab the max value
I have a table in a database with one column containing dates and another
From this question:- https://stackoverflow.com/questions/1342611/is-there-a-webservice-api-to-grab-a-screenshot-of-another-website and some other questions/google I got some results like:-- http://www.bitpixels.com/
I would like to grab the prices of products from newegg. heres an example
I want to grab the value of a hidden input field in HTML. <input

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.