"Perl Best Practices", by Conway. Chapter 4. "Use interpolating string delimiters only for strings that actually interpolate."
I think the reasoning there is so that you don't unexpectedly get interpolation when you don't expect it. IMO, it's easier to always expect interpolation, as more often than not it's desired, and use single quotes only when it's clearer.
| [reply] |
If it helps at all, about 6 months ago I went into a perl refresher course everyone on the team had to take. One of the issue was that the people who really did not program in perl could not understand when to use ' versus ".
Of course 'text\n' will print out text\n on the screen when the programmer most likely meant to do just text with a new line. The argument came down to:
Do you want to explicity Expand by default, or not Expand by default. It comes down to what you are programming, and for what use.
If what you are programming will be expanding varibles a lot, then use " and make your life easier. If you want to make sure not to expand varibles, etc, use ' by default.
My guess is, most programmers will go with " because it's lazyer and works 99% of the time.
Even smart people are dumb in most things...
| [reply] |
There is no runtime difference unless there is a variable being interpolated, in which case only double quotes are appropriate. The perl parser treats them the same otherwise:
perl -MO=Deparse -e ' $a = "foo"; $b = ''foo''; $c = q{foo}'
$a = 'foo';
$b = 'foo';
$c = 'foo';
perl -MO=Deparse -e ' $a = "$foo"; $b = q{$foo};'
$a = "$foo";
$b = '$foo';
| [reply] [d/l] [select] |