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


In reply to Re: Win32 ->Replacement->{Text} more than 255 characters by kcott
in thread Win32 ->Replacement->{Text} more than 255 characters by 3dbc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.