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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:45:17+00:00 2026-06-10T06:45:17+00:00

I am working on a Perl script, but I am having an issue I

  • 0

I am working on a Perl script, but I am having an issue I can’t really overcome. Here is my code:

my @rowses = ();


while ( @list = $sth->fetchrow_array())
{
    %row = ();

    if($list[30] == 1) 
      %row = (
            cod_cliente => $list[1],
            rag_soc => $list[2], 
            p_iva => $list[11],
            IDanagrafica => $list[0],
            tabella => $tab,
            IDanagraficaE => $list[0],
            tabellaE => $tab,
            checkbox => "checked",
            );
    $LOL = \%row;
    print $cgi->p($LOL);
}
else
{
    %row = (
            cod_cliente => $list[1],
            rag_soc => $list[2], 
            p_iva => $list[11],
            IDanagrafica => $list[0],
            tabella => $tab,
            IDanagraficaE => $list[0],
            tabellaE => $tab,
            checkbox => "",
            );
    $LOL = \%row;
    print $cgi->p($LOL);
}

push (@rowses, \%row);
}

 $template->param(table => \@rowses);   
$template->param(tab => $tab);

When I try to print, for debugging, the reference to a row ($LOL), it prints nothing, and when I print the reference at @rowses, it is an array full of all the same hash, the last one the fetched by from the statement.

The weird is, if I print a hash row per time, without referencing it, it prints them well, and all of them.

I am doing that for passing the array reference, containing all the hashes, to a TMPL_LOOP, and print them; but it print a long list of only the last row fetched.

Thanks in advance to everyone who will help me.

  • 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-10T06:45:19+00:00Added an answer on June 10, 2026 at 6:45 am

    Your %row is the same variable for each iteration of the while loop. You store just the reference to it in @rowses, which means if you change %row, all the references point to the changed hash. You should define a new %row for each iteration of the loop, e.g. by using

    my %row;
    

    indead of

    %row = ();
    

    Why $LOL is not printed: If the first argument to p is a hash reference, it is interpreted as the attributes of the <p>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a Perl script using WWW-Mechanize. Here is my code:
I have been working in a Perl script to read log files, but none
I'm working on a Perl script where the user adds a number of set
I'm working in a Perl script and I'd like to use named parameters to
I am working on a perforce-perl script that creates labels. Due to repeated execution
I have a working perl script that grabs the data I need and displays
Trying to get a simple test perl script working. Have the following files/folder structure
I have some regexes in a Perl script that are correct but slow. I
I have a list of arguments to pass into a Perl script, using ARGV
I'm working on a Perl script which is called from a server side include

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.