in reply to QuoteMeta in perl
Example usages:
Without quotemeta, the following would not match. It would try (and fail) to match a digit.
$not_a_regexp = '\\d'; # The 2 chars: \d $not_a_regexp_quoted = quotemeta($not_a_regexp); # The 3 chars: \\d $not_a_regexp =~ /^$not_a_regexp_quoted\z/; # Matches.
Without quotemeta, eval would try to execute '''., which is invalid Perl.
$not_code = "'"; # ' $not_code_quoted = quotemeta($not_code); # \' $string = eval "'$not_code'"; # '
|
|---|