Test YAML dump:
./jperl -MYAML -e 'print Dump({ hello => "world", numbers => [1,2,3] })'Test YAML round-trip:
./jperl -MYAML -e 'my $data = { hello => "world", numbers => [1,2,3] }; print Dump(Load(Dump($data)))'Test JSON encode:
./jperl -MJSON -e 'print encode_json({ hello => "world", numbers => [1,2,3] })'Test JSON pretty print:
./jperl -MJSON -e 'my $json = JSON->new->pretty(1); print $json->encode({ hello => "world", numbers => [1,2,3] })'Write and read YAML file:
./jperl -MYAML -e 'DumpFile("test.yml", { hello => "world" }); print Dump(LoadFile("test.yml"))'Write and read JSON file:
./jperl -MJSON -e 'use JSON; my $data = { hello => "world" }; open my $fh, ">", "test.json"; print $fh encode_json($data); close $fh; open my $in, "<", "test.json"; my $json = do { local $/; <$in> }; print encode_json(decode_json($json))'Or more simply:
./jperl -MJSON -E 'my $data = { hello => "world" }; say encode_json($data)'time perl -MBenchmark -e 'timethis(200000, sub { my $sum = 0; $sum += $_ ** 2 for 1..1000 });'
timethis 200000: 6 wallclock secs ( 6.02 usr + 0.03 sys = 6.05 CPU) @ 33057.85/s (n=200000)
real 0m6.267s
user 0m6.077s
sys 0m0.051stime ./jperl -MBenchmark -e 'timethis(200000, sub { my $sum = 0; $sum += $_ ** 2 for 1..1000 });'
timethis 200000: 1 wallclock secs ( 1,59 usr + 0,02 sys = 1,61 CPU) @ 124488,04/s (n=200000)
real 0m2.374s
user 0m2.791s
sys 0m0.200s