i read the Q a little different than my other, fellow monks did - so, i'm gonna answer it this way.(Can't hurt. Someone may need the info, regardless.)
the way i take it, is that you're reading from say - a flatfile (.txt) database - trying to swap out the perl in favour of html, so it can be read by a browser or otherwise converted to html. In other words, you're not exchanging "newlines" but the perl command-like (meta-)characters that represent newlines (\n).
if i'm not mistaken...
perl considers the / / in a regex the same as it does double-quotes " " - which means, they're interpolated (carry their full worth -
variables are substituted for their values, etc). So, exchanging \n would be exchanging an actual newline - rather than newline
characters.
(i know, it's confusing.)
anyways...
if i were exchanging "\n" for "<br>\n", i'd make sure, that the characters were all turned off ("just characters") and not something
with more meaning.
like...
my $comments =~ s/\\n/\<\.br\>\\n/;
that extra slash before the special (meta) character tells perl to "turn the special meaning off" (or rather "escape the character" in perl lingo.)
or, i believe, single-quotes, which don't interpolate - might work as well -
my $comments =~ s/'\n'/'\n<.br>\n'/;
(i almost never use that method, so can't be 100% sure, how well it works.)
in short... if you have a text file, that's got actual tabs, line-breaks, etc in them - try regexes joost and tachyon are suggesting. If you have in the file the actual characters...
hi\t my name is Count Dracula\n
use this.
update...just for the record, i don't think the angle brackets <> need to be escaped. (oops)
In reply to Re: Substituting Newline Characters
by wolfi
in thread Substituting Newline Characters
by bkiahg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |