How to debug a Perl application with eclipse

Source: Internet
Author: User
Tags perl debugger

Before you start

This tutorial describes the debugging capabilities provided by the Eclipse's EPIC plug-in, which provides a rich debugging environment that can be used for the epic PERL development environment and integrated with this development environment. This tutorial assumes that the reader understands the ECLIPSE environment and has experience using Perl.

About this tutorial

EPIC combines two systems that help the Perl application test process: The REGEXP and the debugger. REGEXP is an interface to test Perl regular expressions. Regular expressions are a major part of many Perl applications, but ensuring the correctness of an expression is a very complex issue. Using the EPIC RegExp view, you can test and modify regular expressions based on known data to check the results.

The EPIC Perl Debugger is a more traditional tool that is fully integrated into the ECLIPSE environment. In addition to testing localized scripts, the EPIC debugger can also be used to debug the Web and execute Perl scripts remotely, and is therefore the ideal tool for many environments.

This tutorial will explain how to import and move large applications, simplify the application view to make your code easier to understand, and thus easier to debug. It also introduces the EPIC debugging environment, which is entirely within Eclipse and provides a complete debugging environment for standard scripts, CGI scripts, and regular expressions.

Prerequisite conditions

To start using EPIC, you need to meet the following prerequisites:

Eclipse V3.1 or 3.0

Java™ Technology V1.3, 1.4, or later

Perl V5.8.6 or later. Perl is included in most UNIX®, linux® installations, and Mac OS X. ActivePerl is used on Windows®.

Eclipse's EPIC Plugin

Padwalker Perl module. ActiveState version is also available.

Traditional Perl Debugging Techniques

Before introducing EPIC, let's take a look at the traditional debugging techniques used by Perl, which are readily available and do have some advantages. But they also have their own limitations. Understanding its limitations can help you understand why you need a better debugging environment.

Introduction to Debugging in Perl

If you ask a typical Perl programmer how to debug its application, he will probably tell you that he simply uses simple output statements to dump information as the program executes. For example, you can add a simple statement to the loop to output the value that you are calculating or processing, as shown in Listing 1.

Listing 1. Debugging with an output statement

my $sth = $dbh->prepare($query);

$sth->execute();

while(my $row = $sth->fetchrow_hashref())
{
   print STDERR Dumper($row);

   printf('%s, %s (%s)<br/>',
       $row->{album},
       $row->{artist},
       $row->{genre});
}
$sth->finish();

In this case, you have output a row dump from the database (MySQL) load to STDERR. STDERR is easy to use because on UNIX hosts you can relocate the STDERR output to the log file while the other outputs are positioned to normal output as usual.

The dumper () function in the example actually outputs the structure of any variable, including embedded and nested arrays, hashes, and other content. The output format is the same as the structure you manually generated. This function (Data::D part of the Umper module) is useful as a way to output variables in a format suitable for human reading, or to write a read-back structure, using eval () to recreate a new variable.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.