perldebtut.html

来自「perl教程」· HTML 代码 · 共 736 行 · 第 1/5 页

HTML
736 行
字号
        DB<11> r
        scalar context return from main::f2c: 0.722222222222221</pre>
<p>Looks good, let's just continue off the end of the script:</p>
<pre>
        DB&lt;12&gt; c
        0.72 c 
        Debugged program terminated.  Use q to quit or R to restart,
        use O inhibit_exit to avoid stopping after program termination,
        h q, h R or h O to get additional info.</pre>
<p>A quick fix to the offending line (insert the missing parentheses) in the
actual program and we're finished.</p>
<p>
</p>
<hr />
<h1><a name="placeholder_for_a__w__t__t">Placeholder for a, w, t, T</a></h1>
<p>Actions, watch variables, stack traces etc.: on the TODO list.</p>
<pre>
        a</pre>
<pre>
        w</pre>
<pre>
        t</pre>
<pre>
        T</pre>
<p>
</p>
<hr />
<h1><a name="regular_expressions">REGULAR EXPRESSIONS</a></h1>
<p>Ever wanted to know what a regex looked like?  You'll need perl compiled with
the DEBUGGING flag for this one:</p>
<pre>
        <span class="operator">&gt;</span> <span class="variable">perl</span> <span class="operator">-</span><span class="variable">Dr</span> <span class="keyword">-e</span> <span class="string">'/^pe(a)*rl$/i'</span>
        <span class="variable">Compiling</span> <span class="variable">REx</span> <span class="string">`^pe(a)*rl$'
        size 17 first at 2
        rarest char
         at 0
           1: BOL(2)
           2: EXACTF &lt;pe&gt;(4)
           4: CURLYN[1] {0,32767}(14)
           6:   NOTHING(8)
           8:   EXACTF &lt;a&gt;(0)
          12:   WHILEM(0)
          13: NOTHING(14)
          14: EXACTF &lt;rl&gt;(16)
          16: EOL(17)
          17: END(0)
        floating `</span><span class="string">'$ at 4..2147483647 (checking floating) stclass `EXACTF &lt;pe&gt;'</span>
        <span class="variable">anchored</span><span class="operator">(</span><span class="variable">BOL</span><span class="operator">)</span> <span class="variable">minlen</span> <span class="number">4</span>
        <span class="variable">Omitting</span> <span class="variable">$`</span> <span class="variable">$&amp;</span> <span class="variable">$'</span> <span class="variable">support</span><span class="operator">.</span>
</pre>
<pre>
        EXECUTING...</pre>
<pre>
        Freeing REx: `^pe(a)*rl$'</pre>
<p>Did you really want to know? :-)
For more gory details on getting regular expressions to work, have a look at
<a href="../../lib/Pod/perlre.html">the perlre manpage</a>, <a href="../../lib/Pod/perlretut.html">the perlretut manpage</a>, and to decode the mysterious labels (BOL and CURLYN,
etc. above), see <a href="../../lib/Pod/perldebguts.html">the perldebguts manpage</a>.</p>
<p>
</p>
<hr />
<h1><a name="output_tips">OUTPUT TIPS</a></h1>
<p>To get all the output from your error log, and not miss any messages via
helpful operating system buffering, insert a line like this, at the start of
your script:</p>
<pre>
        <span class="variable">$|</span><span class="operator">=</span><span class="number">1</span><span class="operator">;</span>
</pre>
<p>To watch the tail of a dynamically growing logfile, (from the command line):</p>
<pre>
        tail -f $error_log</pre>
<p>Wrapping all die calls in a handler routine can be useful to see how, and from
where, they're being called, <a href="../../lib/Pod/perlvar.html">the perlvar manpage</a> has more information:</p>
<pre>
        <span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="variable">$SIG</span><span class="operator">{</span><span class="string">__DIE__</span><span class="operator">}</span> <span class="operator">=</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="keyword">require</span> <span class="variable">Carp</span><span class="operator">;</span> <span class="variable">Carp::confess</span><span class="operator">(</span><span class="variable">@_</span><span class="operator">)</span> <span class="operator">}</span> <span class="operator">}</span>
</pre>
<p>Various useful techniques for the redirection of STDOUT and STDERR filehandles
are explained in <a href="../../lib/Pod/perlopentut.html">the perlopentut manpage</a> and <a href="../../lib/Pod/perlfaq8.html">the perlfaq8 manpage</a>.</p>
<p>
</p>
<hr />
<h1><a name="cgi">CGI</a></h1>
<p>Just a quick hint here for all those CGI programmers who can't figure out how
on earth to get past that 'waiting for input' prompt, when running their CGI
script from the command-line, try something like this:</p>
<pre>
        &gt; perl -d my_cgi.pl -nodebug</pre>
<p>Of course <a href="../../lib/CGI.html">the CGI manpage</a> and <a href="../../lib/Pod/perlfaq9.html">the perlfaq9 manpage</a> will tell you more.</p>
<p>
</p>
<hr />
<h1><a name="guis">GUIs</a></h1>
<p>The command line interface is tightly integrated with an <strong>emacs</strong> extension
and there's a <strong>vi</strong> interface too.</p>
<p>You don't have to do this all on the command line, though, there are a few GUI
options out there.  The nice thing about these is you can wave a mouse over a
variable and a dump of its data will appear in an appropriate window, or in a
popup balloon, no more tiresome typing of 'x $varname' :-)</p>
<p>In particular have a hunt around for the following:</p>
<p><strong>ptkdb</strong> perlTK based wrapper for the built-in debugger</p>
<p><strong>ddd</strong> data display debugger</p>
<p><strong>PerlDevKit</strong> and <strong>PerlBuilder</strong> are NT specific</p>
<p>NB. (more info on these and others would be appreciated).</p>
<p>
</p>
<hr />
<h1><a name="summary">SUMMARY</a></h1>
<p>We've seen how to encourage good coding practices with <strong>use strict</strong> and
<strong>-w</strong>.  We can run the perl debugger <strong>perl -d scriptname</strong> to inspect your
data from within the perl debugger with the <strong>p</strong> and <strong>x</strong> commands.  You can
walk through your code, set breakpoints with <strong>b</strong> and step through that code
with <strong>s</strong> or <strong>n</strong>, continue with <strong>c</strong> and return from a sub with <strong>r</strong>.  Fairly
intuitive stuff when you get down to it.</p>
<p>There is of course lots more to find out about, this has just scratched the
surface.  The best way to learn more is to use perldoc to find out more about
the language, to read the on-line help (<a href="../../lib/Pod/perldebug.html">the perldebug manpage</a> is probably the next
place to go), and of course, experiment.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Pod/perldebug.html">the perldebug manpage</a>, 
<a href="../../lib/Pod/perldebguts.html">the perldebguts manpage</a>, 
<a href="../../lib/Pod/perldiag.html">the perldiag manpage</a>,
<em>dprofpp</em>,
<a href="../../lib/Pod/perlrun.html">the perlrun manpage</a></p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Richard Foley &lt;<a href="mailto:richard@rfi.net">richard@rfi.net</a>&gt; Copyright (c) 2000</p>
<p>
</p>
<hr />
<h1><a name="contributors">CONTRIBUTORS</a></h1>
<p>Various people have made helpful suggestions and contributions, in particular:</p>
<p>Ronald J Kimball &lt;<a href="mailto:rjk@linguist.dartmouth.edu">rjk@linguist.dartmouth.edu</a>&gt;</p>
<p>Hugo van der Sanden &lt;<a href="mailto:hv@crypt0.demon.co.uk">hv@crypt0.demon.co.uk</a>&gt;</p>
<p>Peter Scott &lt;<a href="mailto:Peter@PSDT.com">Peter@PSDT.com</a>&gt;</p>

</body>

</html>

⌨️ 快捷键说明

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