Using quote-like-operators or quotes in the perl's printf
perl
Solution
You can use `qq()` as an alternative double quote method, such as when you have double quotes in the string. For example:
"\"foo bar\""
Looks better when written
qq("foo bar")
When in the windows cmd shell, which uses double quotes, I often use `qq()` when I need interpolation. For example:
perl -lwe "print qq($foo\n)"
The `qq()` operator -- like many other perl operators such as `s///`, `qx()` -- is also handy as you demonstrate because it can use just about any character as its delimiter:
qq[this works]
qq|as does this|
qq#or this#
This is handy for when you have many different delimiters in the string. For example:
qq!This is (not) "hard" to quote!
As for best practice, I would say use whatever is more readable.
Problem
Reading perl sources I saw many times the next construction: ``` printf qq[%s\n], getsomestring( $_ ); ``` But usually it is written as ``` printf "%s\n", getsomestring( $_ ); ``` The question: - is here any "good practice" what is the correct way, and if yes - when is recommended to use the longer `qq[...]` vs the `"..."` - or it is only pure TIMTOWTDI? The perlop doesn't mention anything about this.