Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re: Re: Re: Re: should this backspace removal code be done better?

by antirice (Priest)
on Oct 05, 2003 at 08:27 UTC ( #296677=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: should this backspace removal code be done better?
in thread should this backspace removal code be done better?

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


Comment on Re: Re: Re: Re: Re: Re: should this backspace removal code be done better?
Download Code
Re: Re: Re: Re: Re: Re: Re: should this backspace removal code be done better?
by shenme (Priest) on Oct 05, 2003 at 10:18 UTC
    Hell yes!   It's over 4 times faster than even my attempt, with your repair making it correct.   Gratuitous benchmark below:
                   Rate     smack    new1      uk  badkcams othersmack
    smack         188/s        --    -96%    -97%      -97%       -99%
    new1         5088/s     2607%      --     -8%      -23%       -86%
    uk           5517/s     2835%      8%      --      -16%       -85%
    badkcams     6594/s     3409%     30%     20%        --       -82%
    othersmack  37394/s    19797%    635%    578%      467%         --
                
                   Rate     smack    new1      uk  badkcams othersmack
    smack        42.6/s        --    -23%    -29%      -43%       -93%
    new1         54.9/s       29%      --     -8%      -27%       -91%
    uk           59.6/s       40%      9%      --      -21%       -90%
    badkcams     75.0/s       76%     37%     26%        --       -88%
    othersmack    626/s     1372%   1040%    951%      735%         --
    
    (See shenme's scratchpad for oogly program)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-09-03 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls