Substitutions

At one job site where I worked, I encountered a number of problems caused by improperly formatted Makefiles. The problems were caused by

  • Lines that began with eight spaces rather than a tab— The make program is picky about this and insists on a tab.

  • Lines that ended in a continuation character (\) followed by whitespace— This means that although the line looked like it was continued, it wasn’t.

To get things working, I turned to Perl to solve the problem by writing a Makefile fixing script.

The script read the Makefile one line at time and wrote out a corrected Makefile. I then used the Perl s//<flag> operator to perform a substitute edit on the line.

The general form of it is

$line =~ s/<old>/<new>/<flag>;
where <old > is the ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.