5 ms·
Bad boy! >hello|goodbye >| >>Result is 'hello|goodbye' >That's a nice dog you have there. >. >>Result is '' I usually handle this wi
by nevinera 16y ago
Bad boy!
>hello|goodbye
>|
>>Result is 'hello|goodbye'
>That's a nice dog you have there.
>.
>>Result is ''
I usually handle this with:
my $pattern = '\\'.substr($in,0,1);
$in =~ s/$pattern//g;
but it still doesn't feel safe. String operations in perl usually do what you want, but be careful with them!
- jerf 16y ago$in =~ s/\Q$remove\E//g; man perlre, search for \Q. When \Q and \E'ing a variable like that, a literal "\E" in the variable value can not escape from the outer \Q.
- deleted 16y ago[deleted]
- shabble 16y agoperl -pe'BEGIN { $x = quotemeta(shift) } s/$x//g;' should do what you want. `quotemeta' is the function that does the escaping for your properly. I was hoping to be able to use tr///, since it seems like it was built for this, but it creates its conversion tables at compile time, so there's no chance to interpolate the argument without some nasty nasty eval'ing.
- nevinera 16y agoYeah, tr was my instinct as well.. Thanks for quotemeta, it helps with something I'm working on right now!