What's your expected output? Because here it kind of looks like you want:

{ "mike":20, "johndeo@/test.com":test }
which doesn't make much sense.

One easy way to make json structure in perl, is to simple encore perl structures using JSON:

use JSON; my %data = (name => "Mike", age => 20, email => "mike@perlmonks.org", +pass => "IAmGroot"); print encode_json(\%data); #edited thanks to marto __DATA__ {"age":20,"pass":"IAmGroot","email":"mike.org","name":"Mike"}

NB: be careful with double quotes, @ should be interpreted as the sigil of an array variable, even though here it is not for some reason. Simple quotes would be better.

Edit: the fact that @/ (a punctuation variable) is not interpolated is actually documented in perlop

"Punctuation" arrays such as @* are usually interpolated only if the name is enclosed in braces @{*}, but the arrays @_ , @+ , and @- are interpolated even without braces.


In reply to Re: strings to json by Eily
in thread strings to json by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.