Enter h or 'h h' for help, or 'man perldebug' for more help. Matthew Lock Matthew Lock Nice little debate here about the perl debugger too perlmonks. Please review your answer — Eugen Konkov. So in short, Perl wants you to code like it's ? Here is an even more efficient way to debug: do not program at all. Now, let's go back to the real world. I hope you can understand that if people asked anything like "how do I debug perl", that would most likely indicate that the "careful thought" tool failed in the first place.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions.
Use the command line to run your script. Dumping variables to the browser allows you to test their values. Make use of an interactive debugger.
Verifying Syntax If your code does not parse or compile, it will never execute correctly. Remember that if you use taint mode which you probably do with all of your scripts , you must also pass the -T parameter to avoid the following error: myScript. As a result, use the perl -wcT calendar. When you have an issue, you may typically find a lot of important information by reviewing these logs.
This file may be found at:. Errors are appended to the bottom of the log; you should keep an eye on it while you test your CGI script. Regrettably, this implies that the debugger can only be used via the command line. Although this is not the typical environment for CGI scripts, as we showed before, it is not straightforward to replicate the CGI environment.
Saving a CGI object to a query file, initializing any other environment variables you might require, such as cookies, and then running your CGI script like this is the best method to do it. Although many more tools are available, you can debug all of your CGI scripts with only these instructions. To understand how to navigate the debugger, practice stepping through programs that you already know work properly.
Because the debugger does not modify your files, you cannot break a working script by inputting an incorrect command. The -e switch takes a quoted string of Perl code and executes it. For example:. This saves typing and makes the code cleaner:. If you ever need to check which version of Perl is installed on your system, use the -v switch:.
Quick tip: if you need detailed information about the installed Perl version, use a capital: -V instead. Modules can be loaded at the command line too. For instance to download and print the PerlTricks. If you need to import functions from a module, use an equals sign followed by a comma separated list of function names. This one is pretty simple: use -w to turn on warnings.
This can be incredibly helpful when code is not behaving the way you think it should. Warnings can help you identify issues that would otherwise be hard to spot:. Turning on warnings quickly identifies the issue:. Take this example:.
0コメント