To compile a C++ project, I want to write a perl script to compile my program and see if the compilation went wrong or not. If the compiler gives any compilation error, I’ll need to perform some other task.
The perl script will be something like this:
@l1 = `find . -name '*.c'`;
@l2 = `find . -name '*.cpp'`;
@l3 = `find . -name '*.cc'`;
my $err;
my $FLAGS = "-DNDEBUG"
push(@l , @l1, @l2, @l3);
chomp(@l);
foreach (@l) {
print "processing file $_ ...";
$err = `g++ $_ $FLAGS`;
if($err == something) {
#do the needful
}
}
so what should be something?
You should check
$?instead, afterg++....perlvar
So you should check if
g++returned0(success) ornon-zero.