The regex you showed us is using a backslash escape for "#" (which doesn't really need to be escaped), whereas you need escapes for open the parens. (Also, you're using a backslash in the replacement string, which would only be needed for getting a literal $ or @.)
And maybe it's just a typo in your post, but you seem to be using the =~ operator twice, which seems wrong - since you're modifying $_, you don't need it at all.
Yet another point: since you are only changing one character (# to *), you should use a "look-ahead assertion" for the other characters in the pattern.
Finally, to top it off, you put a backslash escape in front of the forward-slash character that was supposed to be the middle delimiter for the "s///' operator, so perl only sees two of the three forward-slashes as delimiters.
Try it like this:
foreach ( @lines ) {
s/#(?=<-\(0N<-\(s3T)/*/g;
push(@newlines,$_);
}
(Update: Admittedly, using the look-ahead assertion in this case feels a bit uncomfortable, because you might get it confused with the look-behind syntax:
/(?<=preceding_part)target_part/
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.