I think we may need more context from your post. Define "newline". Are we talking about a legitimate newline from a native text file on your OS, or something provided from a web browser (as might be seen by a multi-line input field in a CGI script, which is what I suspect is the case here). If it's the former, s/\n/<br>/g will do the job. If it's the latter, in my experience, line breaks here tend to be encoded using an ASCII CR, not a "newline". In that case, something like s/\cM/<br>/g is probably what you want. YMMV. | [reply] [d/l] [select] |
Since you're putting real newline tags in, it's quite possible
that other people might look at these entries. With that in
mind, your substitute should keep things readable. Suppose
my input looks like this:
Foo
Bar
Foobar
Then the actual string is "Foo\nBar\nFoobar\n".
If I just ran a simple s/\n/<br>/g on the string,
I'd get this output:
Foo<br>Bar<br>Foobar<br>
Clearly this would get illegible after 20 or so entries. So
use a subtitute like this instead: s/\n/<br>\n/g
Your output should look like this:
Foo<BR>
Bar<BR>
Foobar<BR>
-Ted | [reply] [d/l] [select] |
instead using a 'br' in each line, you could print the tag 'pre' and put the whole data in it, that way you would save some bytes in your dbase.
IMHO of course!
#!/jpsama/bin/perl
| [reply] |
If your input string is like so: "one\ntwo\nthree" then
all you need is s/\n/<BR>/g;
if you're reading it in a line at a time, you can
chomp and join. (Or not chomp and sub and join) | [reply] [d/l] |
The good ole oneliner approach:
$myString =~ s/\n/ /g; | [reply] |
Here's a quick one (untested):
my $char = '<BR>';
s/\n/$char/g;
Mick | [reply] [d/l] |