http://www.perlmonks.org?node_id=11159510

frank1 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Problem with doubles results
by Corion (Patriarch) on May 17, 2024 at 17:51 UTC

    Please post the actual code together with its actual output. The code you posted cannot produce the output you show:

    SELECT name country gender FROM tbl_U WHERE location = ?

    This is not valid SQL.

    { "info": "\t\t\t\t\t\t \n<p>John UK Male</p> \n<p>Kieth UK Male</p>" ...

    This output cannot be produced by

    $json_msg .= <<HTML; <p>$name $country $gender</p> HTML

    ... as this line does not contain any tabs.

    You may want to learn about scoping and where to put your variable declarations. Or at least think about why you are appending to $json_msg, instead of simply setting it to the desired value.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Problem with doubles results
by NERDVANA (Curate) on May 17, 2024 at 20:36 UTC
    You declared my %hash outside of the loop, so each time you push @updated_data, \%hash you get a reference to the same hash. So, it will be an array of many references to the final value of the hash on the last loop iteration.

    Declare my %hash inside the loop to get a new one each time.