Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Substituting Newline Charactersby wolfi (Scribe) |
on Mar 16, 2004 at 04:54 UTC ( [id://336929]=note: print w/replies, xml ) | Need Help?? |
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... (i know, it's confusing.) anyways... like...
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 Section
Seekers of Perl Wisdom
|
|