Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Use of single quotes versus double quotes

by chromatic (Archbishop)
on Dec 08, 2006 at 19:13 UTC ( [id://588675]=note: print w/replies, xml ) Need Help??


in reply to Use of single quotes versus double quotes

Which book is that? If it really says that, I want to get it fixed. (It should say "clarity's sake" instead.)

By the way, there are almost no huge time savings in micro-optimizations when you're doing IO.

Replies are listed 'Best First'.
Re^2: Use of single quotes versus double quotes
by lokiloki (Beadle) on Dec 08, 2006 at 19:36 UTC
    My apologies... I must have misread something. I just went through my Perl books and couldn't find anything. There was SOME reference to preferring single quoted strings over double quoted strings. But I can't find it... I think I may have imagined my own reasons for doing this: "oh, single quoted strings don't have to find the values of variables" Well, shoot, here I was going through and changing my doubles to singles thinking I was getting huge time savings
      "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.
        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...
      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';
Re^2: Use of single quotes versus double quotes
by blahblahblah (Priest) on Dec 10, 2006 at 04:26 UTC
    I remember reading something along these lines in Programming Perl, 2nd edition. It was in a section near the end that listed tips on optimization. (I'm not saying the book was wrong, maybe it was just worded in a way that led me to the same misunderstanding as lokiloki.)

    ... I just looked at the 3rd edition in my safari bookshelf, and I see that it's chapter 24.2, Efficiency, that I'm thinking of -- but I don't see anything about quoting in this current edition.

    Joe

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://588675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found