Perl - removing hash links

I'm just wondering if I can get some help with dereferencing in Perl?

I have a while loop where I query DB and repeat what I return. Then I write the data I need to the hash and push the hash into an array. All of this is part of the JSON string.

However, I can only click on the hash link, not the hash (I tried all kinds of things), that is, if the loop goes (for example) 3 times, I get the same thing that appears 3 times in JSON, I try PUT.

Here is the 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!

+3
source share
2 answers

-, , ( while). , : . , . , my %sig_hash , .

script, . ; my %h .

my @data;

for (1..3){
    my %h;              # New hash for each iteration of the loop.
    $h{a} = 10 * $_;
    $h{b} = 20 * $_;
    push @data, \%h;
}

use Data::Dumper;
print Dumper(\@data);
+6

, FMc, while.

my $json = new JSON::XS;
my $json_text = JSON::XS->new->decode(shift->content);
my $sig_num = 0;

while ($query_handle->fetch) {
  my $sig_hash;
  $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;

, ,

my $json = new JSON::XS;
my $json_text = JSON::XS->new->decode(shift->content);
my $sig_num = 0;

while ($query_handle->fetch) {
  push @{$json_text->{data}{mail}{signatures}}, {
    position => 'below',
    signature_text => $sig,
    signature_name => "Signature ".++$sig_num,
    signature_default => JSON::XS::true,
  };
}

return $json_text;
+1
source

All Articles