Sure, why not :) I did it long before crockford published JSON, long before anyone was using "AJAX" and there was a jQuery, when we called it DHTML :)

#!/usr/bin/perl -- ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END if " -otr -opr - +ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; use Data::Dumper(); use Safe; my $futz = do { my %ro = 1 .. 2; my %sham = 3 .. 4; my %bo = ( a => \%ro, b => \%ro, c => \%sham ); \%bo; }; ddd( $futz ); ddd( SafestUndumper( ppp( $futz ) ) ); dd( $futz ); dd( SafestUndumper( pp( $futz ) ) ); exit( 0 ); sub ppp { use Data::Dumper(); return Data::Dumper->new( [@_] )->Sortkeys( 1 )->Purity( 1 )->Inde +nt( 0 ) ->Useqq( 1 )->Dump . '$VAR1;'; } ## end sub ppp sub ddd { print ppp( @_ ), "\n"; } ## end sub ddd sub SafestUndumper { use Safe; my $s = Safe->new; # http://perl5.git.perl.org/perl.git/blob?f=regen/opcodes $s->permit_only( "anonlist", "anonhash", "pushmark", # perlcall says "PUSHMARK macro tells Perl to make a mental note of th +e current stack pointer." "const", "undef", "list", "lineseq", "padany", "leaveeval", # needed for Safe to operate, is safe without +entereval # needed for self-referentialnes "sassign", "rv2sv", "rv2hv", "helem", # dd-style do-block self-referentialnes "enter", "null", ); $s->reval( @_ ); } ## end sub SafestUndumper __END__ $VAR1 = {"a" => {1 => 2},"b" => {},"c" => {3 => 4}};$VAR1->{"b"} = $VA +R1->{"a"};$VAR1; $VAR1 = {"a" => {1 => 2},"b" => {},"c" => {3 => 4}};$VAR1->{"b"} = $VA +R1->{"a"};$VAR1; do { my $a = { a => { 1 => 2 }, b => 'fix', c => { 3 => 4 } }; $a->{b} = $a->{a}; $a; } do { my $a = { a => { 1 => 2 }, b => 'fix', c => { 3 => 4 } }; $a->{b} = $a->{a}; $a; }

In reply to Re: Perl data notation (PSON/JSON/SafestUndumper) by Anonymous Monk
in thread Perl data notation by rje

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.