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

📄 ch15_03.htm

📁 用perl编写CGI的好书。本书从解释CGI和底层HTTP协议如何工作开始
💻 HTM
📖 第 1 页 / 共 2 页
字号:
main::(Dev:Pseudo:7):	my $q = new CGI;  DB&lt;1&gt;</pre></blockquote><p>The debugger can be intimidating at first, but it is very powerful.To help you get going, <a href="ch15_03.htm#ch15-28900">Table 15-1</a> shows a brief<a name="INDEX-3075" /><a name="INDEX-3076" />summary of all the basic commands you needto know to debug a script. You can debug all of your CGI scripts withjust these commands, although there are many more features actuallyavailable. Practice walking through scripts that you know work inorder to learn how to move around within the debugger. The debuggerwill not change your files, so you cannot damage a working script bytyping a wrong command.</p><p>Complete documentation for the <a name="INDEX-3077" />Perl debugger is available in the<em class="citetitle">perldebug</em> manpage, and a quick reference forthe complete set of commands is available by typing<tt class="literal">h</tt> within the debugger.</p><a name="ch15-28900" /><h4 class="objtitle">Table 15-1. Basic Perl Debugger Commands </h4><table border="1"><tr><th><p>Command</p></th><th><p>Description</p></th></tr><tr><td><p><tt class="literal">s</tt></p></td><td><p>Step; Perl executes the line listed above the prompt, stepping intoany subroutines; note that a line with multiple commands may take afew steps to evaluate.</p></td></tr><tr><td><p><tt class="literal">n</tt></p></td><td><p>Next; Perl executes the line listed above the prompt, stepping overany subroutines (they still run; Perl waits for them to finish beforecontinuing).</p></td></tr><tr><td><p><tt class="literal">c</tt></p></td><td><p>Continue to the end of the program or the next break point, whichevercomes first.</p></td></tr><tr><td><p><tt class="literal">c 123</tt></p></td><td><p>Continue up to line 123; line 123 must contain a command (it cannotbe a comment, blank line, the second half of a command, etc.).</p></td></tr><tr><td><p><tt class="literal">b</tt></p></td><td><p>Set a breakpoint at current line; breakpoints halt execution causedby <tt class="literal">c</tt>.</p></td></tr><tr><td><p><tt class="literal">b 123</tt></p></td><td><p>Set a breakpoint at line 123; line 123 must contain a command (itcannot be a comment, blank line, the second half of a command, etc.).</p></td></tr><tr><td><p><tt class="literal">b my_sub</tt></p></td><td><p>Set a breakpoint at the first executable line of the<tt class="function">my_sub</tt> sub.</p></td></tr><tr><td><p><tt class="literal">d</tt></p></td><td><p>Delete a breakpoint from the current line; takes same arguments as<tt class="literal">b</tt>.</p></td></tr><tr><td><p><tt class="literal">D</tt></p></td><td><p>Deletes all breakpoints.</p></td></tr><tr><td><p><tt class="literal">x $var</tt></p></td><td><p>Display the value of <tt class="literal">$var</tt> in list and scalarcontexts; note that it will recurse down complex, nested datastructures.</p></td></tr><tr><td><p><tt class="literal">r</tt></p></td><td><p>Return from the current sub; Perl finishes executing the currentsubroutine, displays the result, and continues at the next line afterthe sub.</p></td></tr><tr><td><p><tt class="literal">l</tt></p></td><td><p>List the next 10 lines of your script; this command can be usedsuccessively.</p></td></tr><tr><td><p><tt class="literal">l 123</tt></p></td><td><p>List line 123 of your script.</p></td></tr><tr><td><p><tt class="literal">l 200-300</tt></p></td><td><p>List lines 200 through 300 of your script.</p></td></tr><tr><td><p><tt class="literal">l my_sub</tt></p></td><td><p>List the first 10 lines of the <tt class="function">my_sub</tt> sub.</p></td></tr><tr><td><p><tt class="literal">q</tt></p></td><td><p>Quit.</p></td></tr><tr><td><p><tt class="literal">R</tt></p></td><td><p>Restart the script in the debugger.</p></td></tr></table></div><a name="ch15-19-fm2xml" /><div class="sect3"><h3 class="sect3">15.3.5.2. ptkdb</h3><p>Another option is<em class="emphasis">ptkdb</em><a name="INDEX-3078" /> <a name="INDEX-3079" /> (see <a href="ch15_03.htm#ch15-65096">Figure 15-1</a>), the Perl/Tk debugger, which is available onCPAN as <em class="emphasis">Devel-ptkdb</em>. It allows you to debug yourscripts with a graphical interface. It also allows you to debug yourCGI interactively as they are running.</p><a name="ch15-65096" /><div class="figure"><img width="481" src="figs/cgi2.1501.gif" height="374" alt="Figure 15-1" /></div><h4 class="objtitle">Figure 15-1. Debugging a CGI script with ptkdb</h4><p>In order to use <em class="emphasis">ptkdb</em>, you need two things.First, you need access to an X Window server;<a href="#FOOTNOTE-21">[21]</a> the<a name="INDEX-3080" />X Window System is included with most Unixand compatible systems; commercial versions are available for otheroperating systems as well. Second, the web server must have<a name="INDEX-3081" /><a name="INDEX-3082" />Tk.pmmodule, available on CPAN, which requires Tk. Tk isa<a name="INDEX-3083" /> <a name="INDEX-3084" /> graphics toolkit that istypically distributed with the Tcl scripting language. You can obtainTcl/Tk from <a href="http://www.scriptics.com/">http://www.scriptics.com/</a>. For moreinformation on using Perl<a name="INDEX-3085" />with Tk via Tk.pm,refer to <em class="citetitle">Learning Perl/Tk</em> by Nancy Walsh (O'Reilly &amp; Associates,Inc.).</p><blockquote><a name="FOOTNOTE-21" /><p>[21]In theX Window System, you run an X Window <em class="emphasis">server</em>locally, which displays programs that you may executeremotely. The use of "server" in this context issometimes confusing, since you typically use a <em class="emphasis">client</em>to interact with remote systems.</p></blockquote><p>In order to debug a CGI script with <em class="emphasis">ptkdb</em>, beginyour CGI scripts as follows:</p><blockquote><pre class="code">#! /usr/bin/perl -d:ptkdbsub BEGIN {    $ENV{DISPLAY} = "your.machine.hostname:0.0" ;}</pre></blockquote><p>You should replace <tt class="literal">your.machine.hostname</tt> with thehostname or IP address of your machine. You can use<tt class="literal">localhost</tt> if you are running an X Window sessionon the web server.</p><p>You also need to allow the web server to display programs on your XWindow server. On Unix and compatible systems, you do so by addingthe registering the hostname or IP address of the webserver with the<tt class="command">xhost</tt><a name="INDEX-3086" /><a name="INDEX-3087" /> command:</p><blockquote><pre class="code">$ xhost www.webserver.hostnamewww.webserver.hostname being added to access control list</pre></blockquote><p>You can then access your CGI script via a browser, which should opena debugging window on your system. Note that your web browser maytime out if you spend much time interacting with the debugger withoutyour script producing output.</p></div><a name="ch15-20-fm2xml" /><div class="sect3"><h3 class="sect3">15.3.5.3. ActiveState Perl debugger</h3><p>The final option is available only to <a name="INDEX-3088" /><a name="INDEX-3089" /><a name="INDEX-3090" /> <a name="INDEX-3091" />Win32 users.ActiveState distributes a graphical Perl debugger with their PerlDevelopment Kit (PDK), shown in <a href="ch15_03.htm#ch15-43713">Figure 15-2</a>.</p><a name="ch15-43713" /><div class="figure"><img width="481" src="figs/cgi2.1502.gif" height="441" alt="Figure 15-2" /></div><h4 class="objtitle">Figure 15-2. Debugging a CGI script with the ActiveState Perl debugger</h4><p>Once installed, using the<em class="emphasis">-d</em><a name="INDEX-3093" /> flag with <tt class="command">perl</tt>invokes this debugger instead of the standard Perl debugger. It canalso be invoked when running CGI scripts if you are logged into theweb server.</p><p>You can obtain the <a name="INDEX-3094" /><a name="INDEX-3095" />PDK and correspondingdocumentation from ActiveState's web site at <a href="http://www.activestate.com/">http://www.activestate.com/</a>. The PDK is acommercial product, but as of the time this book was written,ActiveState <a name="INDEX-3096" /> <a name="INDEX-3097" />offers a free <a name="INDEX-3098" /> <a name="INDEX-3099" /> <a name="INDEX-3100" />seven-day trial.</p></div></div><hr align="left" width="515" /><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch15_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td width="172" valign="top" align="right"><a href="ch16_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td width="172" valign="top" align="left">15.2. Perl Coding Techniques</td><td width="171" valign="top" align="center"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td width="172" valign="top" align="right">16. Guidelines for Better CGI Applications</td></tr></table></div><hr align="left" width="515" /><img src="../gifs/navbar.gif" alt="Library Navigation Links" usemap="#library-map" border="0" /><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area href="../index.htm" coords="1,1,83,102" shape="rect" /><area href="../lnut/index.htm" coords="81,0,152,95" shape="rect" /><area href="../run/index.htm" coords="172,2,252,105" shape="rect" /><area href="../apache/index.htm" coords="238,2,334,95" shape="rect" /><area href="../sql/index.htm" coords="336,0,412,104" shape="rect" /><area href="../dbi/index.htm" coords="415,0,507,101" shape="rect" /><area href="../cgi/index.htm" coords="511,0,601,99" shape="rect" /></map></body></html>

⌨️ 快捷键说明

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