Thanks Travis, I'll give your code a shot, but every time I use backticks my 
computer crashes.
  Thanks to John and Tom for suggesting "do" and "eval".  I read up on those.  
I don't understand them entirely, but I  experimented.  They seem to  
accomplish about the same thing.  I  wrote two one-line programs:    print 
eval(system('perl -c  nextprogramtoexecute.pl'));  and
      print do {system('perl -c  nextprogramtoexecute.pl')};
      They both give the same  results.  When nextprogramtoexecute.pl  has a 
syntax error I see the error message (saying it's in line 3 near such and  such 
or whatever) and the next line has the number 65280.  (Which is 255 x 2 to the 
eighth I  noticed.)  And when  nextprogramtoexecute.pl has sound syntax, I see 
the message "nextprogramtoexecute.pl  syntax OK", and the next line has the 
number 0.  Getting a zero, or some number, of course, is all the basis I  need. 
 What I'm inclined to do then, is  write something like
      unless (eval(system('perl -c  nextprogramtoexecute.pl')))
    {require (nextprogramtoexecute.pl)}
      meaning unless there's a syntax  error, run the program (exactly what 
I've been going for).
      It seems like I can do that.  Have I got it?  Since I don't entirely 
understand 'do' and 'eval' I'm afraid I  might be overgeneralizing from these 
examples.   In other words, what if another syntax error also returned zero?  
(Or is it possible some syntax OK message  could return a number other than 
zero?)   In that case I wouldn't be getting what I need.  (I don't need to 
distinguish between different  syntax errors, just know whether or not there is 
one.)
      Fred Kittelmann
        
Travis Thornhill <[EMAIL PROTECTED]> wrote:Actually  if the syntax is good the 
output will contain one line. If there are  errors there will be multiple 
lines. This would work better:
   
  my $progname = "whatever.pl";
  my @output = `perl -c $progname`;
  my $syntax_ok = 0;
  foreach my $line ( @output ) {
      if ( $line =~ /$progname syntax OK/ ) {
          $syntax_ok = 1;
          last;
      }
  }

Travis Thornhill  wrote:
  Would something like this (with backticks) work?
It's probably not as robust as using 'do BLOCK' but it might
work.

#untested
my $progname = "whatever.pl";
my $output = `perl -c $progname`;
if ( $output =~ /$progname syntax OK/ ) {
# It's good
} else {
# It's bad
}

hOURS wrote:
Hi all,
I've  written a PERL program that runs other PERL programs (through 'require'  
statements and what not). It worked fine for a couple tasks I had in  mind, but 
there's an obstacle ahead in the next thing I want to use it  for. The programs 
it will execute may (or may not) have syntax errors.  Asking it to 'require' a 
program with a syntax error will cause the  main program to quit and print out 
the appropriate error message for  that. I don't want that. I want it to keep 
going.
Recently I've  posted questions here about compiling. My thinking was that if 
my main  program were running machine language programs instead, I wouldn't get 
 those syntax errors. (The programs might still be junk, and might give  
peculiar results, but that's ok.) I haven't figured that out yet, but I  
haven’t given up on it either.
However my uncle suggested another  possibility, avoiding any need to compile; 
that I check for syntax  errors first - in which case I can simply go on to the 
next program,  thereby avoiding a shutdown of the main program. This sounded 
nice but  seemed hopeless in practicality (there are so many possible syntax  
errors). But then it occurred to me that PERL already checks for syntax  
errors. It recognizes them of course, but there's also the -c option. I  
thought I could put a line in the main program like
system('perl -c nextprogramtoexecute.pl');
and  check to see if that gives me a syntax OK message or not. But I can't  
figure out how to get a hold of the message. I figured it would be in  STDOUT, 
but I can't figure out how to make use of that. I have a PERL  textbook in 
front of me, but it says precious little about STDOUT. I've  tried capturing 
this in a variable with backticks, qx//, and the open  function with a vertical 
bar. All of those shut down my computer,  saying I performed an illegal 
operation. (Which in itself is another  problem. I mean it's one thing to just 
not work...)
So, many thanks  in advance to anyone who can tell me how to use STDOUT for 
this. Or if  you have another way to read that message before the program 
quits, or  another way to test for syntax errors... that's cool too. But I 
suspect  STDOUT is going to be the best thing.
Fred Kittelmann
P.S. I'm not using UNIX, if that matters.


---------------------------------
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.




---------------------------------
Want to be your own boss? Learn how on Yahoo! Small Business. 

     
---------------------------------
Want to be your own boss? Learn how on  Yahoo! Small Business. 

                
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ 
countries) for 2¢/min or less.

Reply via email to