Script debugger

They have: 314 posts

Joined: Nov 1999

IS there anywhere on the net that will help debug a perl script? IE, telling you what the errors are (or roughly what they are) and where they are etc. I really could do with one.

Also, I had Activestate perl on before I formatted my hdd and whenever I ran any script with a call to open a file it always seemed to mess up. IE, it didnt show any errors or anything, even when ion the net it did mess up. Does it always do this?
Cheers

They have: 193 posts

Joined: Feb 2000

There are quite a few things you can do to check your code.

  1. Add -w to the end of the path to perl. This will print any suntax error that may be found to the log files (I think). Beware: Although your script may work fine, this sometimes prints "useless" info to the log files each time the script is ran. Suggestion: Only use on final script to see if there is anything you could change to make it better.

    Example:

    #!/usr/bin/perl -w
    '

  2. Use the below code at the top of all your scripts (right under the path to PERL). If a 500 error happens, you will not see the standard page. Instead, you will see a page with an explination of what was wrong. Usually this helps, but if your script is really messed up (or other reasons) it will just say "Failed because of complications with scripts" or something like that:

    BEGIN {
    use CGI::Carp qw(fatalsToBrowser);
    }
    '

    Hope that helped.

    Richard

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 193 posts

Joined: Feb 2000

Add a die command to the end of your open calls, that way you know if it is failing.

Example:

$file = "/this/is/a/file.txt";

open(FILE,"<$file") || die "Cannot open file $file.  Reasons: $!";
close(FILE);
'

The above code will print what is in quotations if the open call does not work. It will also exit the script.

Richard

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 314 posts

Joined: Nov 1999

Thanks for your hepl richard, the fatals to browser should be very useful Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.