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 7081427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:55:11+00:00 2026-05-28T06:55:11+00:00

Below is the code my $results = $session->array_of_hash_for_cursor(check_if_receipts_exist, 0, @params); next if( scalar @{$results}

  • 0

Below is the code

my $results = $session->array_of_hash_for_cursor("check_if_receipts_exist", 0, @params);
next if( scalar @{$results} <= 0 );
$logger->info("Retrieved number of records: ".scalar @$results);
foreach my $row( sort { $results->{$b}->{epoch_received_date} cmp $results->{$a}->{epoch_received_date} } keys %{$results} )
      {
       //logic
      }

‘check_if_receipts_exists’ is a SQL query which returns some results. Which I try to execute this, I am getting the following error,
Bad index while coercing array into hash

I am new to Perl. Can someone please point out the mistake I am making?

  • 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-28T06:55:12+00:00Added an answer on May 28, 2026 at 6:55 am

    Is $results a hash reference or an array reference?

    In some places you are using it like an array reference:

    scalar @{$results}
    

    and in other places you are using it like a hash reference:

    $results->{$b}->{...}
    keys %{$results}
    

    It can’t be both (at least not without some heavy overload magic).

    If I can infer from the name of the function that sets $results, it should be a reference to a list of hash references, then a few tweaks will set it right:

    1. Using @{$results} is correct; this expression is “an array of hash references”
    2. The last argument to sort should be a list, but the correct list to pass is @{$results}, not keys %{$results}.
    3. Then the parameters $a and $b inside the sort function will be members of @{$results}, that is, they will be hash references. So the comparison to make is

    $a->{epoch_received_date} cmp $b->{epoch_retrieve_data}

    and not

        $results->{$a}->{...} cmp $results->{$b}->{...}
    

    All together:

    my $results = $session->array_of_hash_for_cursor(
       "check_if_receipts_exist", 0, @params);
    next if !@$results;
    $logger->info("Retrieved number of records: ".@$results);
    for my $row (
        sort {
            $b->{epoch_received_date}
              cmp
            $a->{epoch_received_date}
        } @$results
    ) {
       # logic
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following code in LINQPad and got the results given below: List<string>
I saw some code as below during a peer-code-review session: char *s = new
The code below should print ten results but instead it prints ten test-ite. Why
The code below won't work because of this line $params=array($data); . It needs something
Why does the code below result in org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed? The
I understand that the code below would result segmentation fault because at the cstr
I ended up with this horrible code below, I can't get a better result
currently i obtain the below result from the following C# line of code when
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The below code is very simple. I have a jQuery autocomplete bound to an

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.