Sara has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks , do you see the problem in this pice ,,
if ( ! -f $BASEDIR/nbssoammsg/tdt/src/tdt9999.cxx ) { system ( qq(cd $BASEDIR/nbssoammsg/tdt/src)); for $TDT (split/\s+/,`ls *.tdt`){ system (qq($BASEDIR/nbsstools/tdtgen/bin/tdtgen $TDT)); } else { print "Skipping tdtgen file generation -- if you want to force a regen +\n"; print "of tdt files, delete $BASEDIR/nbssoammsg/tdt/src/tdt9999.cxx\n" +; } } I get the following syintax error : <code> syntax error at c:/Perl/myscript.pl line 315, near "else" syntax error at c:/Perl/myscript.pl line 329, near "}"
thanks

Replies are listed 'Best First'.
Re: syntax error
by Abigail-II (Bishop) on Aug 06, 2002 at 14:22 UTC
    • No quotes around the file name.
    • Bad indentation.
    • There's no closing } for the then part.
    With proper indentation, things would have been clear. (Python does have a point)

    Abigail

Re: syntax error
by mattriff (Chaplain) on Aug 06, 2002 at 14:28 UTC
    Specific to the syntax error -- the curly brace above the else is closing the for() block, not the if() block. So you need another right curly brace there. Then, at the end, there are two right curly braces when you only need one. I reformatted the code to make it easier for me to understand:
    if ( ! -f $BASEDIR/nbssoammsg/tdt/src/tdt9999.cxx ) { system ( qq(cd $BASEDIR/nbssoammsg/tdt/src)); for $TDT (split/\s+/,`ls *.tdt`){ system (qq($BASEDIR/nbsstools/tdtgen/bin/tdtgen $TDT)); } } else { print "Skipping tdtgen file generation -- if you want to force a r +egen\n"; print "of tdt files, delete $BASEDIR/nbssoammsg/tdt/src/tdt9999.cx +x\n"; }
    Another thing -- I don't think the second line is doing what you think it is. If you make a system call to cd, the shell that's spawned changes directories and exits -- your Perl program is in the same directory it was. You should use chdir() to change directories, like:
    chdir("$BASEDIR/nbssoammsg/tdt/src") or error_code_here();
    - Matt Riffle