That is odd...
#!/usr/bin/perl
$string = "a\@b.c\n";
$string =~ s#\Qa@b.c\E#email-address#g;
print $string;
$string2 = "a\@b.c\n";
$string2 =~ s#a\@b\.c#email-address#g;
print $string2;
$string3 = "a\@b.c\n";
$qm3 = quotemeta('a@b.c');
$string3 =~ s#$qm3#email-address#g;
print $string3;
Output:
a@b.c
email-address
email-address
So it seems that method won't work correctly. Perhaps
another Monk can enlighten.
Corion suggests that
\Q$var\E should work as normal;
perhaps change the line that reads:
$code .= "s{\\Q$in\\E}{$out}g"
to read:
$code .= "\$var=quotemeta q{$in}; s{\$var}{$out}g"
for all to be well with the world. And it appears to, as well.
Update:D'oh, messed up the replacement line,fixed
Update:Corion once again points out that the reason for this is because @b gets interpolated before \Q takes effect. I should have realized this was the case.
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.