Hello Fellow Monks, It's been a while, but haven't lost my love for this language and glad to be back.

Problem:

Basically my issue is that I want to write scalars in replace of the tokens, but my scalar is over 255 characters.

Background:

Basically what I'm working on is a big perl script to scour a bunch of data and aggregate it into hundreds of word docs. I'm using a template doc by identifying substitutions within the template as ##token_strings##, searching for them and replacing them. I think this approach would be helpful to anyone trying to automate the generation of word documents based on a predefined template with perl. A template is a doc you've already formatted with all the bells and whistles you need, but then need to mass produce them based on the script.

Further Details:

One of my buggy problems is that I'm having a weird win32 error when trying to replace Microsoft Word text strings with strings greater than 255 characters, any ideas on an alternative approach?

Trying to do the following and hit an issue with scalar size
my $doc = $Word->Documents->Open($_[0]) || die("Unable to open documen +t ", Win32::OLE->LastError()); # Open document #my $doc = $MSWord->Documents->Open({FileName=>$_[0]}); # Exit nicely if we couldn't open doc return unless $doc; # Content object my $content=$doc->Content; #my $selection = $word->Selection; print "Finding Tokens...\n"; # Find object my $find=$content->Find; $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}=$cant_be_more_than_255
Below is a code snippet, not complete script, but if you know Win32::ole I think it should make sense what my problem is, but please do let me know if you have any questions. I have the error it generates too if that's helpful, i.e. when it's not within the if / else and perl tries to write the scalar which is over 255 chars.
if (length($service_screens) > 255) { print "These are $service_screens string is over 255 \n\n" +; $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}="Service Screens"; #$doc->ActiveWindow->Selection->MoveDown(wdLine,1); #$doc->ActiveWindow->Selection->TypeText("Can't write scal +ar because it's over 255 chars??"); $find->Execute({Replace=>$wd->{wdReplaceAll},Forward=>$wd- +>{True}}); } else { $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}=$service_screens; #$doc->ActiveWindow->Selection->MoveDown(wdLine,1); #$doc->ActiveWindow->Selection->TypeText("This line should + be after the Service screen"); $find->Execute({Replace=>$wd->{wdReplaceAll},Forward=>$wd- +>{True}}); }
Thanks.
- 3dbc

In reply to 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.