Small problem. You may want to clear out the leading \b's after the while statement. Like many others on this thread, you've been bitten by the terminal's evaluation of \b.

#!/usr/bin/perl -l $s = "\bt\b\bhello"; sub smack { $a = $s; $a =~ s/^\cH+//; 1 while ($a =~ s/[^\cH]\cH//g); $a; } sub othersmack { $a = $s; 1 while ($a =~ s/[^\cH]\cH//g); $a =~ s/^\cH+//; $a; } print smack(); print othermack(); print "smack correct" unless grep {ord==ord"\b"} split//,smack(); print "othersmack correct" unless grep {ord==ord"\b"} split//,othersma +ck(); __END__ output: hello hello othersmack correct

However, getting rid of the alternation is a good bit quicker. =)

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1


In reply to Re: Re: Re: Re: Re: Re: should this backspace removal code be done better? by antirice
in thread should this backspace removal code be done better? by smackdab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":