in reply to Parse the text file output and delete files

You might be interested to read up on the awk utility, which is one of the inspirations for Perl and still a very good tool for dealing with requirements like these.   An awk program basically consists of a set of regular-expressions and blocks of code that are to be executed when the associated pattern is matched.   awk reads the source-file line by line, testing each line.   Not surprisingly, this translates easily and directly to Perl programs.

First the explanation, then the sample code.   In this problem, there are basically two “lines of interest.”   There is the executing: line, which contributes the name of the last script executed, and the ERROR at line, which tells us that we have something to do (with that name).

The meat-and-potatoes of the program will therefore look something like this:   (extemporaneous code, untested)

#!/usr/bin/perl use strict; use warnings; $| = 1; my $filename; while (<>) { if ( /^executing: \@(.*)/i ) { $filename = $1; } else if ( /^ERROR at/i ) { unlink $filename or warn "can't unlink $filename: $!\n"); } }

Note the following:

  1. For brevity, and maybe also to allow the easy writing of “awk-script replacement” programs, Perl uses a number of cryptic variables such as $_ and $!.   For more information, see perldoc perlvar.   The if statements implicitly refer to “the last line read,” which is $_ and populated by the while loop ... actually by the equally-cryptic “<>” therein.
  2. The regular expressions shown here use a number of features.   (See perldoc perlre et al):
    • The /i suffix makes them case-insensitive.
    • The use of ^ to “anchor” the pattern to the beginning of the string.
    • The use of a parenthesized group to capture what matches inside the group and to make it available, in this case, as $1.

HTH ...