in reply to Wanted: humanly readable `script` output
Actually, I'm a little surprised that this works. I would think that modifying $text before the last match position in a m//g loop would screw things up.my $text = "abcDE\x08\x08xyz\x08Z"; # \x08 is the backspace character while ($text =~ m/\x08/g) { substr($text, pos($text)-2, 2, ''); } print $text, "\n"; # emits: abcxyZ
Update: A slightly more optimized version:
while ($text =~ m/(\x08+)/g) { substr($text, $pos-2*length($1), 2*length($1), ''); } print $text, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Wanted: humanly readable `script` output
by mrslopenk (Acolyte) on May 04, 2008 at 20:11 UTC | |
by pc88mxer (Vicar) on May 04, 2008 at 20:33 UTC | |
by mrslopenk (Acolyte) on May 04, 2008 at 20:46 UTC | |
by mrslopenk (Acolyte) on May 04, 2008 at 20:25 UTC | |
by loris (Hermit) on May 05, 2008 at 06:23 UTC | |
by ikegami (Patriarch) on May 05, 2008 at 06:40 UTC | |
|
Re^2: Wanted: humanly readable `script` output
by moritz (Cardinal) on May 04, 2008 at 20:03 UTC | |
by GrandFather (Saint) on May 05, 2008 at 01:43 UTC | |
by Anonymous Monk on May 05, 2008 at 02:02 UTC |