timpoiko has asked for the wisdom of the Perl Monks concerning the following question:
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})/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;
man perlop is not very helpful.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.
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Side effects of an /e modifier
by Corion (Patriarch) on Jan 29, 2020 at 14:13 UTC | |
|
Re: Side effects of an /e modifier
by hippo (Archbishop) on Jan 29, 2020 at 14:11 UTC | |
|
Re: Side effects of an /e modifier
by k-mx (Scribe) on Jan 29, 2020 at 17:17 UTC |