in reply to Win32 ->Replacement->{Text} more than 255 characters

G'day 3dbc,

Welcome back!

I don't have access to your platform (Win32::* modules, "MSWord", etc.) but, as I see no one has replied in over eight hours, here's at least a technique you could use, to split your replacement string into smaller parts, and then do multiple replacements.

#!/usr/bin/env perl use strict; use warnings; use constant { MAX_STR_LEN => 5, TOKEN => '#T#', }; use Test::More; my @tests = ( ['#T#', 'abc', 'abc'], ['#T#', 'abcd', 'abcd'], ['#T#', 'abcde', 'abcde'], ['#T#', 'abcdef', 'abcdef'], ['#T#', 'abcdefg', 'abcdefg'], ['#T#', 'abcdefghijklm', 'abcdefghijklm'], ['', 'abcdefghijklm', ''], ['xyz', 'abcdefghijklm', 'xyz'], ['MNO #T# PQR', 'abcdefghijklm', 'MNO abcdefghijklm PQR'], ['MNO#T# PQR', 'abcdefghijklm', 'MNOabcdefghijklm PQR'], ['MNO #T#PQR', 'abcdefghijklm', 'MNO abcdefghijklmPQR'], ['MNO#T#PQR', 'abcdefghijklm', 'MNOabcdefghijklmPQR'], ['MNO##T##PQR', 'abcdefghijklm', 'MNO#abcdefghijklm#PQR'], ); plan tests => scalar @tests; for (@tests) { my ($target, $replace, $expect) = @$_; my $newstr = $target; my @replacements; if (index($newstr, TOKEN) != -1) { for (my $pos = 0; $pos < length $replace; $pos += MAX_STR_LEN) + { push @replacements, substr $replace, $pos, MAX_STR_LEN; } for my $replacement (@replacements) { substr $newstr, index($newstr, TOKEN), 0, $replacement; } substr $newstr, index($newstr, TOKEN), length TOKEN, ''; } is($newstr, $expect, "'$target' -> '$expect'"); }

Output:

1..13 ok 1 - '\#T\#' -> 'abc' ok 2 - '\#T\#' -> 'abcd' ok 3 - '\#T\#' -> 'abcde' ok 4 - '\#T\#' -> 'abcdef' ok 5 - '\#T\#' -> 'abcdefg' ok 6 - '\#T\#' -> 'abcdefghijklm' ok 7 - '' -> '' ok 8 - 'xyz' -> 'xyz' ok 9 - 'MNO \#T\# PQR' -> 'MNO abcdefghijklm PQR' ok 10 - 'MNO\#T\# PQR' -> 'MNOabcdefghijklm PQR' ok 11 - 'MNO \#T\#PQR' -> 'MNO abcdefghijklmPQR' ok 12 - 'MNO\#T\#PQR' -> 'MNOabcdefghijklmPQR' ok 13 - 'MNO\#\#T\#\#PQR' -> 'MNO\#abcdefghijklm\#PQR'

— Ken