Yes, that is one of the ways I attempted to capture the text. It turns out that @array never gets "cleared out", and accumulates all of the text from all of the files, printing ever larger blocks of text as it goes through the whole list of text files. I have tried pushing the contents of @array into another array at different points in the loops, and then clearing @array out, but I don't seem to be doing it right. Here is my whole chunk of code - array names have been changed from our examples.
{
local $/ = q{};
for (@ThisFileArray) {
chomp;
push @NewTextArray, qq{<p>$_</p>\n};
}
}
push(@FormattedParagraphs,@NewTextArray);
@NewTextArray = "";
So what do I do to capture all of the paragraphs from one text file which are contained in one pass of @ThisFileArray? I have tried moving the second push into different sections of the loop, and I haven't had any luck. I still wind up accumulating all of the text from all of the text files.
Thanks for sticking with me this far.
Mark
OK, I figured it out. Turns out it wasn't that hard, and I was already close thanks to you wfsp. Here's the new code that works.
{
local $/ = q{};
for (@ThisFileArray) {
chomp;
push @NewTextArray, qq{<p>$_</p>\n};
}
@FormattedParagraphs = @NewTextArray;
foreach $newline (@FormattedParagraphs) {
$newline =~ s/<p><\/p>//;
}
@NewTextArray = ();
@ThisFileArray = ();
}
Clearing out the original array was what was needed to keep it from accumulating text from subsequent files. Once I put that into the overall loop, everything turned out fine.
I added the foreach loop to go through the resultant output, and take out the extra paragraph marks that were inserted on blank lines. I could probably do the same thing with an if statement before the paragraph gets pushed into the new array. But this works too.
Thanks for all the help!
Mark