From: hOURS <[EMAIL PROTECTED]>
>     Hi,
>       I wrote to the list with this issue before and got some  suggestions, 
> but nothing worked.  I  ended up shelving it, but now would like to try again.
>       I have a thousand scripts I'd like to check for syntax  errors.  (Long 
> story that.)  All I need is a list of which ones have  errors.
>           Some code suggested by John seemed very promising:
>       my $return = do 'PossError1.pl';
>           $return has a value of 1 if the syntax is fine, and the  error 
> message otherwise.  My problems  come when I loop.  When I try:
>           for($number = 1; $number <1000; $number +=1) {
>         $progname = "PossError" . $number . ".pl";
>         my $return = do  $progname;
>         print "$return\n";
>       }
>           I get two difficulties.   1) It doesn't do all one thousand 
> scripts.  For some reason it decides nine is plenty.  I see nine 1s on my 
> screen and the computer  thinks it's done.  2) If one of the  scripts has an 
> error, it won't even do nine.   If the 7th one has an error I'll see 6 1s, an 
> error message,  and then the program hangs.
>           Any suggestions?
>       Fred

There are two problems with this implementation.

First it doesn't check the syntax, it executes the scripts!
And second it (tries to) executes the scripts all in one process. So 
whatever changes in global data does one script make, the later ones 
see.

I think you want something like this:

for my $number (1 .. 1000) {
        my $progname = "PossError" . $number . ".pl";
        if (!-e $progname) {
                print "$progname doesn't exist!\n";
                next;
        }
        my $return = `perl -c $progname`;
        if ($return =~ / syntax OK$/) {
                print "$progname is OK\n";
        } else {
                print "$progname has errors\n";
        }
}

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to