in reply to Use of single quotes versus double quotes
Are there huge time savings
In this case, absolutely none. Both forms are compiled down into constant strings:
% 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
% 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use of single quotes versus double quotes
by gam3 (Curate) on Dec 08, 2006 at 23:31 UTC |