yaml2perl.pl : convert YAML data to a Perl variable (dump) which can be parsed or eval'ed by any Perl script.
Version 0.14
yaml2perl.pl -i "input.yaml" -o "output.perl" --no-escape-unicode --terse --no-indent yaml2perl.pl -e < "input.yaml" > "output.pl" # press CTRL-D when done typing YAML to STDIN # input must be less than 4K long! yaml2perl.pl # Read input from clipboard or write output to clipboard # Only in: Unix / Linux / OSX # (must have already installed xclip or xsel or pbpaste (on OSX)) json2json.pl -e < $(xclip -o) json2json.pl -e < $(pbaste) # write the output to the clipboard for further pasting json2json.pl -i input.json | xclip -i # clicking mouse's middle-button will paste the result
yaml2perl.pl
Options:
--i filename : specify a filename which contains a YAML data structure.
--i filename
--I "string" : specify a string which contains a YAML data structure.
--I "string"
--o outputfilename : specify the output filename to write the result to, which will be as a Perl variable, as a dump, which can be parsed or eval'ed from any Perl script.
--o outputfilename
--escape-unicode : it will escape all unicode characters, and convert them to something like "\u0386". This is the default option.
--escape-unicode
--no-escape-unicode : it will NOT escape unicode characters. Output will not contain "\u0386" or "\x{386}" but "α" (that's a greek alpha).
--no-escape-unicode
--terse / --no-terse : Terse form of output (no $VAR1). The second is the default option.
--terse
--no-terse
--indent / --no-indent : do not use indentation. The first is the default option.
--indent
--no-indent
Input can be read from an input file (--i), from a string at the command line (--I) (properly quoted!), from STDIN (which also includes a file redirection yaml2perl.pl < inputfile.yaml > outputfile.perl
yaml2perl.pl < inputfile.yaml > outputfile.perl
For more information see Data::Roundtrip.
Under Unix/Linux, the maximum number of characters that can be read on a terminal is 4096. So, in reading-from-STDIN mode beware how much you type or how much you copy-paste onto the script. If it complains about malformed input then this is the case. The workaround is to type/paste onto a file and operate on that using --i afile or redirection < afile.
--i afile
< afile
Andreas Hadjiprocopis, <bliako at cpan.org> / <andreashad2 at gmail.com>
<bliako at cpan.org> / <andreashad2 at gmail.com>
To install Data::Roundtrip, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Roundtrip
CPAN shell
perl -MCPAN -e shell install Data::Roundtrip
For more information on module installation, please visit the detailed CPAN module installation guide.