In almost all the Perl solutions posted so far, there is the common denominator while (/.\x08/). I don't like it because it scans again some parts of the string that already have been cleaned up. So I've worked out something using m/\G.../g, that continues scanning where it left off:
my $text="ABC\x08\x08\x08\x08\x08DEFGHIJKL\x08\x08M\x08NOP\x08\x08\x08 +\x08\x08\x08\x08QRST"; while ($text =~ /\G.*?(\x08+)/g) { my $c2r = 2 * length $1; ## number of chars to remove my $st = (pos $text) - $c2r; ## start $st++, $c2r-- while $st < 0; ## maybe there are too many \x08's ne +ar the beginning substr $text, $st, $c2r, ''; ## wipe erased characters as long as +their corresponding \x08's pos $text = $st; ## make \G resume in a sensible place } print "$text\n"; __END__ DEFQRST
--
David Serrano
In reply to Re: ascii problem
by Hue-Bond
in thread ascii problem
by kermit393
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |