Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Sub-initiate needs help getting started

by Wally Hartshorn (Hermit)
on Aug 26, 2003 at 14:59 UTC ( [id://286735]=note: print w/replies, xml ) Need Help??


in reply to Sub-initiate needs help getting started

How does one debug a Perl program containing multiple subroutines that generate HTML pages that use Javascript on the Web (and uses SQL to pull data from the database)?

If you're very lucky, he used some sort of HTML templating module. (HTML::Template is probably the easiest to get started with.) That can help immensely because it avoids having oodles of print statements spewing out HTML code at numerous places in your code.

Unfortunately, I suspect you aren't that lucky.

If you're lucky, the 8,000 line file is done as a separate module (something.pm), with just a short perl program calling the initial subroutine in that module. If that's the case, it's easy to write short perl programs of your own to call subroutines in that module to test things out. For example, if there is a subroutine in the module that accepts an employee name as a parameter and returns that employee's salary, you can easily write a short perl program to call that subroutine, pass it a hard-coded name for testing purposes, and then print out the salary that is returned on the command line. That allows you to debug just that tiny segment of code from the command line, rather than dealing with the entire CGI environment in a web browser.

Unfortunately, I suspect you aren't that lucky in this bit, either.

If the changes you will be making are quite minor, I would recommend making the changes first and verifying that they work before doing any significant structural work.

If the changes are going to be extensive, then I would suggest restructuring the existing code first to make it easier to make the future changes.

Suggested modules: CGI.pm, DBI.pm, HTML::Template, Config::IniFiles, Test::More, HTML::FillInForm, CGI::Application, CGI::Application::ValidateRM. These let you easily read data from a form (via CGI.pm), read from the database (via DBI.pm), display values in an HTML page (via HTML::Template), read from a configuration file (Config::IniFiles), run automated tests to ensure that a routine that you had working earlier hasn't been broken by later changes (Test::More), pre-populate a web form (HTML::FillInForm), handle CGI interactions via run-modes (CGI::Application), and validate data entered in a form (CGI::Application::ValidateRM).

An 8,000 line program without "use warnings" and "use strict" that incorporates HTML, JavaScript, and SQL without modules and automated tests is pretty much a textbook example of what NOT to drop on someone who is new to Perl.

Look on the bright side -- every Perl project you have after this one will be easier! :-)

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://286735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found