[Melbourne-pm] Single vs double quotes: no real difference

Jacinta Richardson jarich at perltraining.com.au
Tue Jun 20 16:50:57 PDT 2006

Sisyphus wrote:
> ----- Original Message ----- 
> From: "Jacinta Richardson"

>> If you mix up your quotes with no clear reason (that is sometimes you use
>> single and other times double for literal data) then the person reading your code
>> will just go nuts.
> I reckon that I mix them up "with no clear reason" ... and I also reckon
> that most others do, too .... but I'm not sure that my reckoning is correct
> :-)

I mentioned the above purely because the biggest argument I could find to use
single quotes instead of double quotes for non-interpolating strings was the one
I gave (help readers of your code know what to expect).

Personally I've never had any difficulty reading strings in (well-formatted)
code and just working out whether they do or probably should interpolate.  Even
looking over the shoulders of our students when they're learning Perl shows that
types of quotes isn't much of a problem.  They're much more likely to forget to
add a semi-colon and then spend a few moments trying to spot where.  Actually to
be accurate they're not usually a problem, however when it comes to displaying
prices they'll usually forget that $9.99 interpolates within double quotes.

Like Joshua, my editor colours strings the same.  I'm more likely to see red and
glance at the string than see " or ' first and then glance at the string.
Fortunately, my editor also highlights variables within strings, which makes
them much easier to see.  So if I see a non-highlighted variable in a string
then I know that's a string with single quotes (or my syntax highlighting is

As I said before, despite being aware of this argument, I use double quotes
pretty much everywhere.  The biggest exception is when I need to embed double
quotes in a string that doesn't need to use interpolation: then I use single
quotes, q{} or qq{} as the occasion warrants.  I suspect you're probably correct
to reckon that lots of programmers mix them up.  If their maintainers have
access to syntax highlighting editors, then they probably won't even notice.

All the best,


   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |

More information about the Melbourne-pm mailing list