in reply to Re: Performance problems on splitting long strings
in thread Performance problems on splitting long strings
An example of davido's in-place string modification combined with boftx's dispatch table handler:
>perl -wMstrict -le "use constant LEN => 5; ;; my $s = '1234598765555553456733333'; print qq{'$s'}; ;; my %dispatch = ( '55555' => sub { return 'x' x length $_[0]; }, ); ;; for (my $offset = 0; $offset < length $s; $offset += LEN) { for (substr $s, $offset, LEN) { $_ = exists $dispatch{$_} ? $dispatch{$_}->($_) : $_ + 2; } } print qq{'$s'}; " '1234598765555553456733333' '1234798767xxxxx3456933335'
Update: Changed example code to also exemplify topicalization of sub-string segment via for-structure (given no longer being quite kosher).
|
|---|