alietzow has asked for the wisdom of the Perl Monks concerning the following question:

Humble newbie bows in obeyance to ask ...

#!/usr/bin/perl -w
# CGI to select data from a SQL database
use CGI;
use strict;
use DBI;
my $q = new CGI;

These are the first six lines of my script select.pl (or select.cgi - I don't think it makes a difference to the debugger). Anyhow, I type
"perl -d select.pl" 


and it drops out in debug mode on line six, thusly....
---------
main::(select.pl:6):    my $q = new CGI;
  DB 1
---------
I didn't want to have to learn perldebug, because it leads into the black hole, but then maybe it's time? What next?

Andrew Lietzow - The ACL Group, Inc.

Replies are listed 'Best First'.
(jeffa) Re: Help with perldebug
by jeffa (Bishop) on May 16, 2002 at 22:23 UTC
    I am assuming that after you run the debugger, you hit 'n'. If this is the case, then that is the expected behavior. 'n' steps over the expression and moves on, and since there is nothing left....

    Try 's' instead, which steps inside.

    Also, 'q' gives a list of available commands. The rest is just plain ole hard work on your behalf. ;)

    UPDATE:
    Yes, assume i did. By 'drops out' i thought you meant you were getting unexpected results. Just do what VSarkiss said. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      When I press 'n" or 's' I get the message. "Can't call method header on an undefined value at showmethemonkey.cgi line 3" I tried to find something on this (to "Just do what VSarkiss said" but I don't find any references to perl debug there. I'm really at a loss here... I'm going to try this same script on another server to see what happens.. Okay... Copied it over to another server that I know can run cgi scripts... (RHL 7.0, Apache 1.3.14, Perl 5.6.1) and I get "Document contains no data". TIA for any help... Andrew L.
Re: Help with perldebug
by VSarkiss (Monsignor) on May 16, 2002 at 22:28 UTC

    Well, when you get the prompt, the debugger is ready for you to type the next command. You can type any Perl expression and it will run it and show you the result. You can also single-step your program, but if those six lines are your entire program, then it'll exit right afterwards. I can't really tell you what to type next since I don't know what you're trying to do.

    There's a nice built-in help to the debugger, but if you've never used it before, perldebug is indeed the thing to read next.

    The debugger is very handy to know because you can also use it as interactive Perl environment (I probably use it more for that than actual debugging). There's a very nice chapter on using it in Effective Perl Programming, one of my favorite Perl books.

    HTH

Re: Help with perldebug
by DigitalKitty (Parson) on May 17, 2002 at 00:08 UTC
    Hi Andrew.

    When I ran your small code sample ( win32 machine, ActiveState Build 631/5.6.1 ), I received the following:

    Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(test.pl:4): my $q = new CGI; DB<1> n 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. DB<1>


    If you would rather not read the perldebug page ( I would suggest doing so anyway. For the educational benefits ), I recommend any one of following books:

    • Beginning Perl - Simon Cozens - Wrox Press
    • Programming Perl - 3rd ed. - O'Reilly
    • Professional Perl Programming - Wrox Press

    All three texts have a chapt. on using the perl debugger. If you don't feel confident ( perl skill wise ), an excellent idea would be to read Learning Perl 3rd ed. first. This is essentially the standard with which perl 'newbies' increase their knowledge.

    My own personal knowledge of the perl debugger is limited, it may help to think of the commands like this:

    'n' allows you to see the order in which the code is being interpreted ( first this then that, etc. ) while 's' is used to step inside.

    Hope this helps,

    -DK
      I posted this accidentally as "Anonymous Monk"... sorry. This statement

      if ($q->param('field') eq "") {&printform()} {&results()}

      gives the error: Use of unitialized value in string eq at select.cgi line 18.
      I'm beyond "showmethemonkey" and I know my CGI's are being processed. So what is wrong with the eq statement?
        Can you post the whole program?
        I suspect the error is in the 'field'. You need the name of the field variable there ( such as name or address ). Like this:

        #!/usr/bin/perl -wT use CGI; use CGI::Carp qw( fatalsToBrowser ); if($q->param('name') eq "") { &printForm(); &results(); }

        Did you declare the fields with 'my' in your CGI app?
        -DK
Re: Help with perldebug
by rinceWind (Monsignor) on May 17, 2002 at 10:33 UTC
    alietzow,

    You might like to try Devel::ptkdb, which is a graphical debugger which works well on CGI scripts.

    Update: have replied to alietzow on the CB.

      Interesting. I returned here today to ask this question yet you have already posted your reply ...

      The Advanced Text editor in KDE helps in visual display but I need a real debugger. When I was working in interpreted Basic (Business Basic BBX and ProvideX), the debugger was built into the interpreter. No help for logic flaws but at least it would catch syntax errors (most of my problems yesterday were typos and missing commas) it would catch syntax errors (misplaced commas, parens, etc. For logic flaws, BBX offered wonderful flowcharting utilities that were a great aid in debugging. Where can I discover more about Devel::ptkdb ? While patiently awaiting your reply, I will scamper over to CPAN and see what is there... Regards. Andrew L.