Yes, but it is eval, unfortunately. eval is dangerous; Never use it with user input!
s[/][\\/]g for $lhs, $rhs;
eval "s/$lhs/$rhs/";
Alternatively,
$rhs =~ s["][\\"]g;
$rhs = q["$rhs"];
s/$lhs/eval $rhs/e;
Probably you should reconsider if you really do want this.
Also, parsing XML with regexes is bad, .* is bad, and $ doesn't do what you think,
Perl 6 changes:
- The new regexes are called rules.
- The e (eval) flag for s/// disappeared. Instead of it, use the generic expression interpolation syntax.
- Expressions are interpolated with {}, so s/foo/bar/e is now s/foo/{bar}/.
- Flags are written in front instead of at the end. s/foo/bar/g is now s:g/foo/bar/.
- $ really matches the end of the string. For the end of the line, use $$.
- Perhaps using XML with rules will be more socially accepted, as there can be an XML compliant grammar.
- The new special variable $/ holds all captures, named and unnamed.
- $1 and friends begin with $0, and are shortcuts for $/[0], $/[1], $/[2], ....
- Capture variables are immediately active, and a backreference is now spelled <$0>.
- You still have to use eval for what you ask for here.
- The s flag disappeared, . always matches any character, including \n. To match any character except \n, use \N.
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.