> -----Original Message-----
> From: hOURS [mailto:[EMAIL PROTECTED] 
> Sent: Monday, March 19, 2007 13:17
> To: Perl Beginners
> Subject: Re: STDOUT
> 
> 
> 
> Jenda Krynicky <[EMAIL PROTECTED]> wrote:  From: hOURS 
> >     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
>     
>     
>     
>   Thanks Jenda,
>   I definitely do just want to check syntax and not execute 
> the scripts.
>     
>   I ran your code.  I think we're getting close.  Here's what 
> happened:
>   For the first 64 scripts, I got either a syntax OK message 
> or an error  message, followed, in all 64 cases, by the "has 
> errors" print  out.  The remaining 936 scripts all gave just 
> the "has errors"  print out.  Why would the program make that 
> choice (the else  portion of the if/else) every time?  Only 
> about 5% of the scripts  have errors.  I happened to know in 
> advance that #17 was the only  one amongst the first 20 with 
> an error.  There seemed to be 4  amongst those first 64 
> scripts.  But even the 60 that gave me a  'syntax OK' message 
> followed it up with the "has errors" choice.   I thought 
> perhaps that second $, between the slashes, in the line:
>    if ($return =~ / syntax OK$/) {
>      shouldn't be there, (after all it doesn't show up on my 
> screen) but deleting that had no effect.
>     
>   I'd rather not print out the syntax OK or error message.  
> It's  redundant info with the subsequent if/else choice.  In 
> any event I  can't imagine why the first 64 behaved 
> differently from the last 936,  though I wouldn't be 
> surprised if 64 being a power of 2 is part of the  explanation.
>   Oh let me also mention I'm using Windows, in case that matters.
>     
        If you are on windows, then see perlfaq8 if ActiveState perl for
how to redirect STDOUT and STDERR when doing backticks. Believe where
you want to be at.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us 
 
>   Thanks much!
>   Fred
>     
>  
> ---------------------------------
> Now that's room service! Choose from over 150,000 hotels 
> in 45,000 destinations on Yahoo! Travel to find your fit.
> 

**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


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


Reply via email to