Why does the perl quotemeta () function behave differently when under a debugger?

I was bitten by this little inconsistent debugger. The quotemeta() function seems to behave differently when called in perl -d

$ perl -e 'print quotemeta("/a/b/c"),"\n"'

The output is \/a\/b\/c , which is correct and as described in perldoc -f quotemeta .

Now that under the debugger the output will be \\/a\\/b\\/c . I thought that some main module that I use overrides the function, although, as verified, it seems that the behavior only happens when under the debugger. A call to CORE::quotemeta() returns the same result.

Can someone enlighten me?

Thanks!

+4
source share
2 answers

quotemeta is a shotgun that avoids all characters other than words, whether they need it or not. The debugger is less heavy; quoting only those characters that need it. (Backslashes, backslashes do not.) More importantly, this only happens when you look at the values, not when you print them. For comparison:

  DB<1> x quotemeta('a/b/c') 0 'a\\/b\\/c' DB<2> p quotemeta('a/b/c') a\/b\/c 
+8
source

I cannot find a link for this, but the perl debugger, when asked to print a line, will rewrite it so that you can insert this safe literal value into the script. Your meaning is true; This is a debugger that adds a backslash. perldoc perldebug has a quote option, you can try to mess it up.

+3
source

All Articles