qsl has asked for the wisdom of the Perl Monks concerning the following question:

Monks,
I found lot of definitons for quotemeta in perl,but i am still confusing that why we have to use that and how to use it.I never found any example regarding this.
The definition is like thisz"Returns the value of EXPR with all non-"word" characters backslashed. (That is, all characters not matching /[A-Za-z_0-9]/ will be preceded by a backslash in the returned string, regardless of any locale settings.) This is the internal function implementing the \Q escape in double-quoted strings"
can anyone let me know how i have to use this.
Thanks,
qsl.

Edited by planetscape - added code tags

( keep:0 edit:6 reap:0 )

Replies are listed 'Best First'.
Re: QuoteMeta in perl
by gopalr (Priest) on Jul 04, 2006 at 09:45 UTC
Re: QuoteMeta in perl
by ikegami (Patriarch) on Jul 04, 2006 at 13:18 UTC

    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'"; # '
Re: QuoteMeta in perl
by planetscape (Chancellor) on Jul 04, 2006 at 12:43 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.