cmiller2005:

In your getLetter routine, you're only telling it to read the first line. Let's reproduce it here with good indentation:

sub getLetter { my $txline; my $letterfile = 'C:\Users\Carl\Documents\NewLetter.txt'; open (INPUT1, $letterfile) or die ("Can't open file"); while ($txline = <INPUT1>) { return $txline; } }

With the indentation cleaned up, the problem becomes obvious: You read a line into $txline, and then immediately return to the caller. You never actually read the rest of the file.

To fix it, you probably want to collect the entire file and return it as a single text string. You can do it like this:

sub getLetter { # Let's start the buffer with an empty string to avoid # an "uninitialized" warning message. my $txline = ""; my $letterfile = 'C:\Users\Carl\Documents\NewLetter.txt'; open (INPUT1, $letterfile) or die ("Can't open file"); while (my $line = <INPUT1>) { # Each time we read $line, we want to add it to the # end of $txline $txline = $txline . $line; } # *now* we have all the data we want in $txline, so we # can return it to the caller return $txline; }

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^8: Mail Merge with Word 2007 and Perl by roboticus
in thread Mail Merge with Word 2007 and Perl by cmiller2005

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.