It's not interpolation.
But '00' is true. The only strings that are false are the empty string, and the string '0'. | [reply] [d/l] [select] |
Interpolation occurs between double quotes or qq and is not involved here (and would not affect the outcome if it was).
Placing quotes around characters makes it a text string, and for false we would need an empty string or a single zero: anything else is true. Numeric zero (with no quotes) is false: use strict;
use warnings;
if ( '00' ) {
print "Yes\n"
}
if ( 00 ) {
print "Yes\n"
}
else {
print "No\n"
}
Gives:Yes
No
Update: correction to wording of a false string. | [reply] [d/l] [select] |
q/STRING/
'STRING'
A single-quoted, literal string. A backslash represents a backslash unless followed by the
delimiter or another backslash, in which case the delimiter or backslash is interpolated.
| [reply] |
Seems like a rather poor choice of word to me. The delimiter or backslash is already present in the string literal, so how can it be interpolation?
| [reply] |
The doc is rather inconsistent, at the start of perlop is the following table:
Customary Generic Meaning Interpolates
'' q{} Literal no
"" qq{} Literal yes
`` qx{} Command yes*
qw{} Word list no
// m{} Pattern match yes*
qr{} Pattern yes*
s{}{} Substitution yes*
tr{}{} Transliteration no (but see below)
<<EOF here-doc yes*
* unless the delimiter is ''.
Note: it says single quotes do not offer interpolation. So, as in most holy books, it depends on which part of perlop you (carefully) read. | [reply] [d/l] |
Perl does try to “DWIM = Do What I Mean.” Which is definitely a two-edged sword sometimes. Just try to write code such that your intentions are perfectly clear ... not so much “to the computer,” but “to you and your fellow humans.” No surprises, nothing clever, no side-effects. The rest is merely Golf.
| [reply] |