in reply to Re^3: Queries for elastic search using perl
in thread Queries for elastic search using perl

Near the bool. Its pushing as a element. Means the array contains two elements bool & the hash. But I expected that as a whole(one) hash.

  • Comment on Re^4: Queries for elastic search using perl

Replies are listed 'Best First'.
Re^5: Queries for elastic search using perl
by Corion (Patriarch) on Jun 29, 2016 at 08:56 UTC

    What do you mean exactly by "near the bool"?

    As posted, I see two data structures. The one you have:

    $VAR1 = ['bool' => { ...

    And the one you say you want:

    $VAR1 = [ 'bool', { ...

    But there is no difference to Perl between the two structures. 'bool' => ... and 'bool', ... are exactly the same. See perlop on the "fat comma".

Re^5: Queries for elastic search using perl
by hippo (Archbishop) on Jun 29, 2016 at 08:57 UTC

    The fat comma is still a comma. The two structures are identical.

      If it is same I am pushing the hash into the @condition_array in line 65 and checking the size of array in the line 67. Its saying the size of array is 2. But as per you said the size should be one right ???

        No, the size should be 2 because your hash has 2 elements: a key and a value. The hash is expanded into a list when pushed onto an array so the array has 2 new values, the first being the key and the second being the value. eg:

        #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 1; my %z = ( a => 'b' ); my @x = ( 'a', 'b' ); my @y = (); push @y, %z; is_deeply (\@x, \@y);

        If you don't want the hash expanded in this way then you must use a reference to it instead when you push it. The reference is then just one element in the resulting array. It will probably help you greatly to have a thorough read of perldsc.