in reply to Re^4: Size of a HASH (with more keys)
in thread Size of a HASH (with more keys)

The best solution would be using a JSON module. :)

The second best is to push @lines, "JSON ENTRY" within the loop, and then to print join ",\n", @lines after the loop.

See join for details.

HTH! :)

Cheers Rolf

(addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^6: Size of a HASH (with more keys)
by David92 (Sexton) on Jul 02, 2014 at 14:12 UTC
    I am trying to find a step by step guide on how to do the JSON encode using CPAN's module. In their library I know it's descriptive.

    But I as I read it quickly, I think they generate only JSON (which is a bit different than JSONP).

    Nevertheless, so If I have a HASH where all the info is stored that I want. How should I create a JSONP with this Module?

    $json_text   = $json->encode( $perl_scalar );

    This is the syntax from CPAN. Is the $perl_scalar my $testHASH in our case?

      > (which is a bit different than JSONP).

      try reading JSONP and explain the difference. You might figure out how to use JSON then! (hint: + padding)

      > Is the $perl_scalar my $testHASH in our case?

      from JSON

      $json_text = to_json($perl_scalar) Converts the given Perl data structure to a json string.

      If you try to understand JSON and Perl Data Structures you will see that they have the exactly same structure with little syntactic differences (enough to justify a module in that case)

      I.o.w. $perl_scalar is a ref to a HoH or HoA or AoH (... and so on) reflecting the JSON structure you desire.

      Please try ...

      • to read the links I gave you,
      • use search engines for example code
      • generally try experimenting with code¹
      ... to improve your coding skills.

      Hope this helped! :)

      Cheers Rolf

      (addicted to the Perl Programming Language)

      update

      ¹) use Data::Dumper or Data::Dump to inspect data structures