Okay. No one actually explains why your regex doesn't work, so I will take a stab at it.
1) If you want to do a substitution the form is $post =~ s/matching bit/replacement bits/modifier bits; (note the s instead of the m- s is for substitute, m is for match)
2) When you start a matching expression with ^ it will match the beginning of the line. $ is for the end of the line. Neither of these are necessary to match a new line character, really. Since the character you are looking for defines where lines begin and end.
3) You probably want to put a modifier or two at the end of your expression to make sure that you match and substitute all of the \n's in your $post. I suggest /sg. Adding s will make the RE treat your entire $post as one string. Adding g will make the RE test and match until it can't find anymore matches-- otherwise it will only match/substitute once.
So just to clarify, I suggest using
$post =~ s/\n/<br>/sg; . And don't be afraid to read the regex docs at
perldoc perlre.
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.