in reply to Re^2: Push values into a hash
in thread Push values into a hash

You keep trying to push \%data. What is that supposed to accomplish?

I don't understand what you're trying to do here. A hash always consists of a key and a value. You at best have a value here, never mind the syntax.

Maybe you want to use a real array, @data instead of a hash?

I think in addition to your code, you should also show what data structure you want at the end.

Replies are listed 'Best First'.
Re^4: Push values into a hash
by Anonymous Monk on Jul 25, 2016 at 16:05 UTC
    Hi, I posted a better sample code to show it better. I would like to end up with json data as:
    ["name:Joe","address:Main Street","phone: 346 20274","email:test1@test +.com"] ...

    thanks!

      Then maybe a first step would be to create the strings:

      "name:Joe"

      This is somewhat weird, because JSON usually doesn't encode information in tagged strings but as "objects" (anonymous hashes in Perl).

      Maybe you can show us an example of your data structure where you have two persons, Joe and Jane?

      Usually, with JSON, you don't build the string but build the appropriate Perl data structure and export that data strucutre as JSON using one of the modules. But until you show us what the data structure should look like, we can't really help you building it.