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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.