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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |