Hi monk-beginner,
First off, I *think* what you mean for the string containing Escapes is:
my $line = "Stopping saslauthd: \x1b[60G[\x1b[0;31mFAILED\x1b[0;39m]\r
+";
The character \x1b is an Escape character, which can alternatively be written as \e.
(It looks like a string you'd see as a result of stopping a service under Linux, and the escape characters it contains are there to display the text in a different, easy-to-read color.)
Next of all, are you just trying to eliminate the escape sequences from your string entirely? For that, perhaps a regular expression will help; for example:
use strict;
use warnings;
my $line = "Stopping saslauthd: \x1b[60G[\x1b[0;31mFAILED\x1b[0;39m]\r
+";
my $noesc = $line;
$noesc =~ s/(\e\[\d+G|\e\[\d+(;\d+)*m|\r*)//g;
print "noesc = '$noesc'\n";
The relevant line here is:
$noesc =~ s/(\e\[\d+G|\e\[\d+(;\d+)*m|\r*)//g;
which means: Assign $noesc to the value of $line, and then remove all occurrences of "<Escape>[<DIGITS>G" or
"<Escape>[<DIGITS>[;<DIGITS>...]m" or
"\r" (carriage-return).
Regular expressions take some time to understand, but they are very powerful entities, and one of the great "power tools" of Perl. The following documentation may be of help for learning more about regular expressions:
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
|