On Sat, Jan 31, 2015 at 1:58 PM, Harry Putnam <[email protected]> wrote:
> I've given myself a headache googling on how to debug a perl script
> that does not run.
>
> Maybe `debug' is the wrong word... I'd love to know if there is a more
> accurage one.
>
> I realize this post is quite a lot of yak, but hoping someone can lay
> out a few steps that will narrow down the problem.
>
> Many, many of the google hits are all about using the debugger, which
> of course is a non-starter if the darn script will not run due to
> compilation errors..
>
> I have about 100 lines or so inside a File::Find:
>
> find (
> sub {
> }, $tdir;
> );
>
> Type of setup. I've beat down the multitudiness errors that perl found
> during compilation. Down to the last one I'm getting.
>
> Before posting all the boring, poorly written code, I thought I'd ask if
> people
> here can outline a few things to do in a case like this.
>
> So far, after getting down to this complilation error:
>
> syntax error at ./t line 96, near "$tdir;"
> Execution of ./t aborted due to compilation errors.
>
> I've gone thru the lines trying to find what is causing the
> error but of course am overlooking it.
>
> Then I pulled just the find(...) part out, put it in its own file.. no
> bang line or nothing and just ran it like: ` perl myscript'.
>
> The error above was the result.
>
> So, how to start breaking down the code to find the problem?
>
> On the surface I can not see a syntactical error at that line.
>
> which looks like this ... snipped:
>
> [...]
>
> } <== incloses an if clause
> } <== incloses a while loop
> close $fh;
> }, $tdir; <== inclusing subroutine
> );
>
>
One good sleuthing tool is perltidy (perltidy.sourceforge.net) which is good
at unraveling a rat's nest of errors to tease out the culprit:
For instance, you'd run: perltidy badlywrittenscript.pl and might get
an error diagnostic file that'd say something like:
The most recent un-matched '{' is on line 7
7: for my $i (@xxx) {
^
12: To save a full .LOG file rerun with -g
---
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/