tags:

views:

57

answers:

2

I am bitten by this little inconsistent debugger behavior. The quotemeta() function seems to behave differently when invoke under perl -d

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

Output is \/a\/b\/c, which is correct and as documented in perldoc -f quotemeta.

Now, when under debugger, the output becomes \\/a\\/b\\/c. I thought some core module I am using was redefining the function though as tested, it seems the behavior only occurs when under the debugger. Calling CORE::quotemeta() returns the same output.

Can somebody enlighten me?

Thanks!

+2  A: 

I can't find a reference for this, but the perl debugger, when asked to output any string, will re-quote it so it's a safe literal value you could paste into a script. Your value is correct; it's the debugger that's adding the backslashes. There is a quote option in perldoc perldebug, you might try messing with that.

MvanGeest
+5  A: 

quotemeta is a shotgun, escaping all non-word characters whether they need it or not. The debugger is less heavy-handed; quoting only those characters that need it. (Backslashes do, forward slashes do not.) More importantly, it only does this when you examine values, not when you print them. Compare:

  DB<1> x quotemeta('a/b/c')
0  'a\\/b\\/c'

  DB<2> p quotemeta('a/b/c')
a\/b\/c
Michael Carman
I've been using the 'x' command since, thanks for pointing out the 'p' command
DexterT.