"I am not a fan of this policy :)"

There seems little point to it. There is a very slight compile time speed penalty to double-quoted strings. This benchmark demonstrates that:

use Benchmark ':all'; cmpthese(250_000, { e_double => sub { eval q{"foo"} }, e_single => sub { eval q{'foo'} }, });

But at runtime, there's no difference, as they compile to the same optree...

$ perl -MO=Concise -e'$x=q{foo}' > single.txt -e syntax OK $ perl -MO=Concise -e'$x=qq{foo}' > double.txt -e syntax OK $ diff -s single.txt double.txt Files single.txt and double.txt are identical $ rm single.txt double.txt

That is not always the case in all programming languages though. The PHP compiler is less smart than the Perl compiler, so in PHP there's a real speed penalty on double-quoted strings...

<?php class Bench { public $name; protected $_start; protected $_finish; public function __construct ($name) { $this->name = $name; } public function start () { if ($this->_start) die("already started"); $this->_start = microtime(true); } public function finish () { if ($this->_finish) die("already finished"); $this->_finish = microtime(true); } public function total_time () { return $this->_finish - $this->_start; } public function run ($callable, $count=1) { $this->start(); for ($i = 0; $i < $count; $i++) call_user_func($callable); $this->finish(); } public function __toString () { return sprintf("%s: %0.6f s", $this->name, $this->total_time() +); } public static function cmpthese ($iterations, $tests) { foreach ($tests as $name => $code) { $bench = new Bench ($name); $bench->run($code, $iterations); $per_second = $iterations / $bench->total_time(); printf("%s: %0.2f /s\n", $bench->name, $per_second); } } } Bench::cmpthese(100000, array( "single quotes" => create_function('', 'return \'foo\';'), "double quotes" => create_function('', 'return "foo";'), ));
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re^2: Perl::Critic and Subroutines by tobyink
in thread Perl::Critic and Subroutines by daugh016

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.