perldoc > B::Deparse

📖 NAME

B::Deparse — Perl compiler backend to produce perl code

🚀 Quick Reference

Use CaseCommandDescription
🔍 Deparse a Perl scriptperl -MO=Deparse prog.plProduce perl source code from compiled structure
🔍 Deparse with extra parenthesesperl -MO=Deparse,-p prog.plShow how perl parses expressions (LISP-like)
🔍 Expand quotes to concatenationperl -MO=Deparse,-q prog.plShow internal handling of double-quoted strings
🔍 Add line declarationsperl -MO=Deparse,-l prog.plInclude #line directives in output
🔍 Deparse with Data::Dumperperl -MO=Deparse,-d prog.plOutput data values using Data::Dumper
🔍 Expand syntax constructionsperl -MO=Deparse,-x5 prog.plTranslate use to BEGIN/require/import
🔍 Deparse a subroutine referenceperl -MO=Deparse -e 'sub foo {...}'Get source code for a subroutine body
🔍 Cuddle else/elsif blocksperl -MO=Deparse,-sC prog.plStyle: cuddle else/elsif/continue
🔍 Custom indent widthperl -MO=Deparse,-si2 prog.plStyle: set indent to 2 columns
🔍 Use tabs for indentationperl -MO=Deparse,-sT prog.plStyle: use tabs for every 8 columns
🔍 Custom void-context placeholderperl -MO=Deparse,-sv'STRING'. prog.plStyle: string for optimized-away constants
🔍 Disable prototype checkingperl -MO=Deparse,-P prog.plDeparse as if no prototypes defined

📋 SYNOPSIS

perl -MO=Deparse[,-d][,-f*FILE*][,-p][,-q][,-l] [,-s*LETTERS*][,-x*LEVEL*] *prog.pl*

📝 DESCRIPTION

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.

While B::Deparse goes to some lengths to try to figure out what your original program was doing, some parts of the language can still trip it up; it still fails even on some parts of Perl's own test suite. If you encounter a failure other than the most common ones described in the BUGS section below, you can help contribute to B::Deparse's ongoing development by submitting a bug report with a small example.

⚙️ OPTIONS

As with all compiler backend options, these must follow directly after the -MO=Deparse, separated by a comma but not any white space.

📦 USING B::Deparse AS A MODULE

📋 Synopsis

use B::Deparse;
$deparse = B::Deparse->new("-p", "-sC");
$body = $deparse->coderef2text(\&func);
eval "sub func $body"; # the inverse operation

📝 Description

B::Deparse can also be used on a sub-by-sub basis from other perl programs.

🆕 new

$deparse = B::Deparse->new(OPTIONS)

Create an object to store the state of a deparsing operation and any options. The options are the same as those that can be given on the command line (see "OPTIONS"); options that are separated by commas after -MO=Deparse should be given as separate strings.

🌐 ambient_pragmas

$deparse->ambient_pragmas(strict => 'all', '$[' => $[);

The compilation of a subroutine can be affected by a few compiler directives, pragmas. These are:

Ordinarily, if you use B::Deparse on a subroutine which has been compiled in the presence of one or more of these pragmas, the output will include statements to turn on the appropriate directives. So if you then compile the code returned by coderef2text, it will behave the same way as the subroutine which you deparsed.

However, you may know that you intend to use the results in a particular context, where some pragmas are already in scope. In this case, you use the ambient_pragmas method to describe the assumptions you wish to make.

Not all of the options currently have any useful effect. See "BUGS" for more details.

The parameters it accepts are:

🔧 coderef2text

$body = $deparse->coderef2text(\&func)
$body = $deparse->coderef2text(sub ($$) { ... })

Return source code for the body of a subroutine (a block, optionally preceded by a prototype in parens), given a reference to the sub. Because a subroutine can have no names, or more than one name, this method doesn't return a complete subroutine definition — if you want to eval the result, you should prepend "sub subname ", or "sub " for an anonymous function constructor. Unless the sub was defined in the main:: package, the code will include a package declaration.

🐛 BUGS

👤 AUTHOR

Stephen McCamant <smcc AT CSUA.EDU>, based on an earlier version by Malcolm Beattie <mbeattie AT sable.uk>, with contributions from Gisle Aas, James Duncan, Albert Dvornik, Robin Houston, Dave Mitchell, Hugo van der Sanden, Gurusamy Sarathy, Nick Ing-Simmons, and Rafael Garcia-Suarez.

B::Deparse
📖 NAME 🚀 Quick Reference 📋 SYNOPSIS 📝 DESCRIPTION ⚙️ OPTIONS 📦 USING B::Deparse AS A MODULE
📋 Synopsis 📝 Description 🆕 new 🌐 ambient_pragmas 🔧 coderef2text
🐛 BUGS 👤 AUTHOR

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-15 21:21 @216.73.216.208
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^