in reply to More efficient way to truncate long strings of the same character
It's my understanding that back references (\1) are a bit slow. What follows are solutions that don't use back references. You'll have to benchmark them to see if they're faster.
#my @chars = grep !$seen{$_}++, $text =~ /./g; my @chars = 'a'..'z'; my ($re) = map qr/$_/, join '|', map "(?<=${_}{3})$_+", map quotemeta, @chars; $text =~ s/$re//g;
#my @chars = grep !$seen{$_}++, $text =~ /./g; my @chars = 'a'..'z'; my ($re) = map qr/$_/, join '|', map "${_}{4,}", map quotemeta, @chars; $text =~ s/($re)/substr($1,0,3)/eg;
#my @chars = grep !$seen{$_}++, $text =~ /./g; my @chars = 'a'..'z'; my ($re) = map qr/$_/, join '|', map "${_}{4,}", map quotemeta, @chars; $text =~ s/$re/substr($text,$-[0],3)/eg;
Update: Fixed bug identified in reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: More efficient way to truncate long strings of the same character
by GrandFather (Saint) on Oct 30, 2008 at 20:36 UTC | |
by ikegami (Patriarch) on Oct 30, 2008 at 23:41 UTC | |
by GrandFather (Saint) on Oct 31, 2008 at 00:00 UTC | |
by ikegami (Patriarch) on Oct 31, 2008 at 00:05 UTC |