Perl - Dereferencing a Hash

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
I am just wondering If I can get some help with dereferencing in Perl?

I have a while loop where I am querying a DB and iterating over what I get back. I then write the data I need into a hash and push the hash into an array. This is all forming part of a JSON string.

However, I can only push the reference to the hash and not the hash itself (I've tried all sorts of things), meaning if the loop goes (e.g.) 3 times, I get the same thing appearing 3 times in the JSON I am trying to PUT.

Here is the code:

Code:
my $json = new JSON::XS;
my $json_text = JSON::XS->new->decode (shift->content);
my $sig_num = 0;
my %sig_hash;
<MySQL Stuff -removed for readability>

while($query_handle->fetch()) 
    {
    $sig_num++;
    $sig_hash{position} = 'below';
    $sig_hash{signature_text} = $sig;
    $sig_hash{signature_name} = 'Signature '.$sig_num;
    $sig_hash{signature_default} = JSON::XS::true;
    push (@{$json_text->{data}->{mail}->{signatures}}, \%sig_hash);
    }
return $json_text;
Thanks for any help!
 
Back
Top Bottom