Gossamer Forum
Home : General : Perl Programming :

Blocks of text in a variable

Quote Reply
Blocks of text in a variable
First time here and I'm looking for help. Short intro, 86 web sites, installed a hundred perl scripts, wrote one. Besides lack of sleep and a racing away hairline, the last is my problem. I would appreciate any insight as to what is happening when...

I wrote a small script that opens a text file with a format like this:

Question|Answer

Then save it to an array.

Notable: The answer may have new lines after each paragraph/chunk of text. Large chuck of text.

I then take a specified html doc, open it and read it in line by line looking for comment markers. While i'm opening the doc I split the two sides of the text file (array) at the "|" then say print $answer at <!--ANSWER-HERE-->. I also print $question at the second marker called <!--QUESTION-HERE-->.

All works well if there are no new lines in the $question variable. If there are, then I wind up with a mixed soup of text.

I tried manipulating the $question variable by first replacing (/\n/\~nl~/g); then before writing (/\~nl~/\<p>/g);

I hope my language is clear here. That's probably part of my problem.

Many Thanks
Tom


Quote Reply
Re: Blocks of text in a variable In reply to
Try putting this in just before you call $question.
Code:
$question =~ s/\n/ /g;

...or if you want to keep the line breaks:
Code:
$question =~ s/\n/<BR>/g;