Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Are there huge time savings

In this case, absolutely none. Both forms are compiled down into constant strings:

  • Double quoted:
    % perl -MO=Concise -e 'print qq{hello, world}' 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <@> print vK ->6 3 <0> pushmark s ->4 4 <$> const(PV "hello, world") s ->5
  • versus single quoted:
    % perl -MO=Concise -e 'print q{hello, world}' 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <@> print vK ->6 3 <0> pushmark s ->4 4 <$> const(PV "hello, world") s ->5 -e syntax OK

The compiler will also fold things like "hello, world\n" and 'hello, world' . "\n" into the same constant strings. It's only when interpolation in a double string comes into play that things change:

% perl -MO=Concise -e 'print qq{hello, $world\n}' a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 9 <@> print vK ->a 3 <0> pushmark s ->4 - <1> ex-stringify sK/1 ->9 - <0> ex-pushmark s ->4 8 <2> concat[t2] sKS/2 ->9 6 <2> concat[t1] sK/2 ->7 4 <$> const(PV "hello, ") s ->5 - <1> ex-rv2sv sK/1 ->6 5 <$> gvsv(*world) s ->6 7 <$> const(PV "\n") s ->8 -e syntax OK

... which is only slightly different to...

% perl -MO=Concise -e 'print qq{hello, } . $world . qq{\n}' a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 9 <@> print vK ->a 3 <0> pushmark s ->4 8 <2> concat[t4] sKS/2 ->9 6 <2> concat[t2] sK/2 ->7 4 <$> const(PV "hello, ") s ->5 - <1> ex-rv2sv sK/1 ->6 5 <$> gvsv(*world) s ->6 7 <$> const(PV "\n") s ->8 -e syntax OK

The above both amount to much the same thing. So basically, you can always use double quotes, interpolate when you need to, and do not worry about performance.

• another intruder with the mooring in the heart of the Perl


In reply to Re: Use of single quotes versus double quotes by grinder
in thread Use of single quotes versus double quotes by lokiloki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found