⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deparse.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>B::Deparse - Perl compiler backend to produce perl code</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>B::Deparse - Perl compiler backend to produce perl code</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#options">OPTIONS</a></li>
	<li><a href="#using_b__deparse_as_a_module">USING B::Deparse AS A MODULE</a></li>
	<ul>

		<li><a href="#synopsis">Synopsis</a></li>
		<li><a href="#description">Description</a></li>
		<li><a href="#new">new</a></li>
		<li><a href="#ambient_pragmas">ambient_pragmas</a></li>
		<li><a href="#coderef2text">coderef2text</a></li>
	</ul>

	<li><a href="#bugs">BUGS</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>B::Deparse - Perl compiler backend to produce perl code</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p><strong>perl</strong> <strong>-MO=Deparse</strong>[<strong>,-d</strong>][<strong>,-f</strong><em>FILE</em>][<strong>,-p</strong>][<strong>,-q</strong>][<strong>,-l</strong>]
        [<strong>,-s</strong><em>LETTERS</em>][<strong>,-x</strong><em>LEVEL</em>] <em>prog.pl</em></p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>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 <strong>-p</strong>
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.</p>
<p>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.</p>
<p>
</p>
<hr />
<h1><a name="options">OPTIONS</a></h1>
<p>As with all compiler backend options, these must follow directly after
the '-MO=Deparse', separated by a comma but not any white space.</p>
<dl>
<dt><strong><a name="item__2dd"><strong>-d</strong></a></strong>

<dd>
<p>Output data values (when they appear as constants) using Data::Dumper.
Without this option, B::Deparse will use some simple routines of its
own for the same purpose. Currently, Data::Dumper is better for some
kinds of data (such as complex structures with sharing and
self-reference) while the built-in routines are better for others
(such as odd floating-point values).</p>
</dd>
</li>
<dt><strong><a name="item__2dffile"><strong>-f</strong><em>FILE</em></a></strong>

<dd>
<p>Normally, B::Deparse deparses the main code of a program, and all the subs
defined in the same file. To include subs defined in other files, pass the
<strong>-f</strong> option with the filename. You can pass the <strong>-f</strong> option several times, to
include more than one secondary file.  (Most of the time you don't want to
use it at all.)  You can also use this option to include subs which are
defined in the scope of a <strong>#line</strong> directive with two parameters.</p>
</dd>
</li>
<dt><strong><a name="item__2dl"><strong>-l</strong></a></strong>

<dd>
<p>Add '#line' declarations to the output based on the line and file
locations of the original code.</p>
</dd>
</li>
<dt><strong><a name="item__2dp"><strong>-p</strong></a></strong>

<dd>
<p>Print extra parentheses. Without this option, B::Deparse includes
parentheses in its output only when they are needed, based on the
structure of your program. With <strong>-p</strong>, it uses parentheses (almost)
whenever they would be legal. This can be useful if you are used to
LISP, or if you want to see how perl parses your input. If you say</p>
</dd>
<dd>
<pre>
    <span class="keyword">if</span> <span class="operator">(</span><span class="variable">$var</span> <span class="operator">&amp;</span> <span class="number">0x7f</span> <span class="operator">==</span> <span class="number">65</span><span class="operator">)</span> <span class="operator">{</span><span class="keyword">print</span> <span class="string">"Gimme an A!"</span><span class="operator">}</span>
    <span class="keyword">print</span> <span class="operator">(</span><span class="variable">$which</span> <span class="operator">?</span> <span class="variable">$a</span> <span class="operator">:</span> <span class="variable">$b</span><span class="operator">),</span> <span class="string">"\n"</span><span class="operator">;</span>
    <span class="variable">$name</span> <span class="operator">=</span> <span class="variable">$ENV</span><span class="operator">{</span><span class="string">USER</span><span class="operator">}</span> <span class="keyword">or</span> <span class="string">"Bob"</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p><code>B::Deparse,-p</code> will print</p>
</dd>
<dd>
<pre>
    <span class="keyword">if</span> <span class="operator">((</span><span class="variable">$var</span> <span class="operator">&amp;</span> <span class="number">0</span><span class="operator">))</span> <span class="operator">{</span>
        <span class="keyword">print</span><span class="operator">(</span><span class="string">'Gimme an A!'</span><span class="operator">)</span>
    <span class="operator">};</span>
    <span class="operator">(</span><span class="keyword">print</span><span class="operator">((</span><span class="variable">$which</span> <span class="operator">?</span> <span class="variable">$a</span> <span class="operator">:</span> <span class="variable">$b</span><span class="operator">)),</span> <span class="string">'???'</span><span class="operator">);</span>
    <span class="operator">((</span><span class="variable">$name</span> <span class="operator">=</span> <span class="variable">$ENV</span><span class="operator">{</span><span class="string">'USER'</span><span class="operator">}</span><span class="operator">)</span> <span class="keyword">or</span> <span class="string">'???'</span><span class="operator">)</span>
</pre>
</dd>
<dd>
<p>which probably isn't what you intended (the <code>'???'</code> is a sign that
perl optimized away a constant value).</p>
</dd>
</li>
<dt><strong><a name="item__2dp"><strong>-P</strong></a></strong>

<dd>
<p>Disable prototype checking. With this option, all function calls are
deparsed as if no prototype was defined for them. In other words,</p>
</dd>
<dd>
<pre>
    <span class="variable">perl</span> <span class="operator">-</span><span class="variable">MO</span><span class="operator">=</span><span class="variable">Deparse</span><span class="operator">,-</span><span class="variable">P</span> <span class="keyword">-e</span> <span class="string">'sub foo (\@) { 1 } foo @x'</span>
</pre>
</dd>
<dd>
<p>will print</p>
</dd>
<dd>
<pre>
    <span class="keyword">sub</span><span class="variable"> foo </span><span class="operator">(</span>\@<span class="operator">)</span> <span class="operator">{</span>
        <span class="number">1</span><span class="operator">;</span>
    <span class="operator">}</span>
    <span class="operator">&amp;</span><span class="variable">foo</span><span class="operator">(\</span><span class="variable">@x</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>making clear how the parameters are actually passed to <code>foo</code>.</p>
</dd>
</li>
<dt><strong><a name="item__2dq"><strong>-q</strong></a></strong>

<dd>
<p>Expand double-quoted strings into the corresponding combinations of
concatenation, uc, ucfirst, lc, lcfirst, quotemeta, and join. For
instance, print</p>
</dd>
<dd>
<pre>
    <span class="keyword">print</span> <span class="string">"Hello, $world, @ladies, \u$gentlemen\E, \u\L$me!"</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>as</p>
</dd>
<dd>
<pre>
    <span class="keyword">print</span> <span class="string">'Hello, '</span> <span class="operator">.</span> <span class="variable">$world</span> <span class="operator">.</span> <span class="string">', '</span> <span class="operator">.</span> <span class="keyword">join</span><span class="operator">(</span><span class="variable">$"</span><span class="operator">,</span> <span class="variable">@ladies</span><span class="operator">)</span> <span class="operator">.</span> <span class="string">', '</span>
          <span class="operator">.</span> <span class="keyword">ucfirst</span><span class="operator">(</span><span class="variable">$gentlemen</span><span class="operator">)</span> <span class="operator">.</span> <span class="string">', '</span> <span class="operator">.</span> <span class="keyword">ucfirst</span><span class="operator">(</span><span class="keyword">lc</span> <span class="variable">$me</span> <span class="operator">.</span> <span class="string">'!'</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Note that the expanded form represents the way perl handles such
constructions internally -- this option actually turns off the reverse
translation that B::Deparse usually does. On the other hand, note that
<code>$x = &quot;$y&quot;</code> is not the same as <code>$x = $y</code>: the former makes the value
of $y into a string before doing the assignment.</p>
</dd>
</li>
<dt><strong><a name="item__2dsletters"><strong>-s</strong><em>LETTERS</em></a></strong>

<dd>
<p>Tweak the style of B::Deparse's output. The letters should follow
directly after the 's', with no space or punctuation. The following
options are available:</p>
</dd>
<dl>
<dt><strong><a name="item_c"><strong>C</strong></a></strong>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -