in reply to Re: ascii problem
in thread ascii problem
That's good, but somehow I just don't like seeing you needing to test with the m// operator, and then perform a nearly equal match for the substitution. To get away with invoking the regexp engine only one time instead of twice on each loop iteration, you can do this instead:
use strict; use warnings; my $test = "hello there ass\x08\x08wesome"; print "BEFORE: $test, ", "(length: " . length($test) . ")\n"; while ($test =~ /.\x08/) { $test = substr( $test, 0, $-[0] ) . substr( $test, $+[0] ); # Note: The preceeding line is the same as: # $test = $` . $'; # but avoids using $` and $', side-stepping the global # performance penalty associated with their use. } print "AFTER: $test, ", "(length: " . length($test) . ")\n";
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: ascii problem
by runrig (Abbot) on Jun 01, 2006 at 21:46 UTC | |
by davido (Cardinal) on Jun 01, 2006 at 23:03 UTC |