Dear monks If I have a function foo(),
sub foo {my $c = shift; $c*=5; return $c;}
All those substitutions works as expected:
$bar =~ s/(\d{2})/joo/msg; $bar =~ s#(\d{2})#jee#msg; $bar =~ s#(\d{2})#foo($1)#mesg; $bar =~ s#(\d{2})#<td>ha ha ha</td>#msg;
But if want to use all things: a /e modifier, html tags and # instead of / (because \-escaped slashes are not very readable)
$bar =~ s#(\d{2})#<td>foo($1)</td>#mesg;
I only get
Bareword found where operator expected at a.pl line 18, near "<td>foo" (Missing operator before foo?) syntax error at a.pl line 18, near "<td>foo" Search pattern not terminated at a.pl line 18.
man perlop is not very helpful.
Any non-whitespace delimiter may replace the slashes. Add space after the "s" when using a character allowed in identifiers. If single quotes are used, no interpretation is done on the replacement string (the "/e" modifier overrides this, however). Note that Perl treats backticks as normal delimiters; the replacement text is not evaluated as a command. If the PATTERN is delimited by bracketing quotes, the REPLACEMENT has its own pair of quotes, which may or may not be bracketing quotes, for example, s(foo)(bar) or s<foo>/bar/. A /e will cause the replacement portion to be treated as a full-fledged Perl expression and evaluated right then and there. It is, however, syntax checked at compile-time. A second "e" modifier will cause the replacement portion to be "eval"ed before being run as a Perl expression.
Tested in Debian Jessie (5.20) and in Debian Buster (5.29).

In reply to Side effects of an /e modifier by timpoiko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.