Also sprach Tad McClellan:
I thought we were talking about useless uses of double quotes,
without regard to what the variable's value is, nor where
the variable is used.
You _never_ need
"$vars"
because
$vars
will always work in its place.
It should, and actually will for all Perl-builtins. Yet there is a
difference on the inside between these two (which makes your points even
more valid):
ethan@ethan:~$ perl -MDevel:
eek
$a = 1;
Dump($a);
Dump("$a");
__END__
SV = IV(0x812b084) at 0x8128ab0
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
SV = PV(0x811e638) at 0x8128ac8
REFCNT = 1
FLAGS = (PADTMP,POK,pPOK)
PV = 0x8123078 "1"\0
CUR = 1
LEN = 2
The stringification will upgrade the scalar value (well, not really
upgrading - the IV part is lost; there are also cases possible where
both PV and IV exist). So
$a = 1;
$b = "$a";
is the equivalent to the other direction as in
$a = "1";
$b = $a + 0;
To make people stop using these casts in cases where they are pointless,
it might be worth to remark that a stringification can make a scalar use
more memory and thus reduce the performance slightly:
ethan@ethan:~$ perl -MDevel::Size=size
print size(1), "\n";
print size("1"), "\n";
__END__
16
26
When doing these conversions in a very unclever way, as in
$a = $b = $c = 1;
@a = ("$a", "$b", "$c");
my $sum;
$sum += $_ for @a;
which means: IV -> PV -> IV, this has runtime-costs since these casts
naturally come at some computational costs that could easily be avoided.
Tassilo