Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl data notation (PSON/JSON/SafestUndumper)

by Anonymous Monk
on Jul 15, 2014 at 20:40 UTC ( #1093770=note: print w/replies, xml ) Need Help??


in reply to Perl data notation

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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1093770]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2022-05-21 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?