Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Perl's quotemeta() function behave differently when under the debugger?

Tags:

debugging

perl

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!

like image 916
DexterT. Avatar asked Dec 22 '22 00:12

DexterT.


2 Answers

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
like image 178
Michael Carman Avatar answered Dec 24 '22 13:12

Michael Carman


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.

like image 35
MvanGeest Avatar answered Dec 24 '22 13:12

MvanGeest