B::Deparse - Perl compiler backend to produce perl code
perl -MO=Deparse[,-uPACKAGE][,-p][,-l][,-sLETTERS] prog.pl
B::Deparse is a backend module for the Perl compiler that generates perl source code, based on the internal compiled structure that perl itself creates after parsing a program. The output of B::Deparse won't be exactly the same as the original source, since perl doesn't keep track of comments or whitespace, and there isn't a one-to-one correspondence between perl's syntactical constructions and their compiled form, but it will often be close. When you use the -p option, the output also includes parentheses even when they are not required by precedence, which can make it easy to see if perl is parsing your expressions the way you intended.
Please note that this module is mainly new and untested code and is still under development, so it may change in the future.
As with all compiler backend options, these must follow directly after the '-MO=Deparse', separated by a comma but not any white space.
if ($var & 0x7f == 65) {print "Gimme an A!"} print ($which ? $a : $b), "\n"; $name = $ENV{USER} or "Bob";
B::Deparse,-p
will print
if (($var & 0)) { print('Gimme an A!') }; (print(($which ? $a : $b)), '???'); (($name = $ENV{'USER'}) or '???')
which probably isn't what you intended (the '???'
is a sign that perl optimized away a constant value).
elsif
, else
, and continue blocks. For example, print
if (...) { ... } else { ... }
instead of
if (...) { ... } else { ... }
The default is not to cuddle.
See the 'to do' list at the beginning of the module file.
Stephen McCamant <alias@mcs.com>, based on an earlier version by Malcolm Beattie <mbeattie@sable.ox.ac.uk>
If rather than formatting bugs, you encounter substantive content errors in these documents, such as mistakes in the explanations or code, please use the perlbug utility included with the Perl distribution.