title: Is the Perl Goatse 'Secret Operator' efficient?
body: <p>The "goatse operator" or the <code>=()=</code> idiom in Perl causes an expression to be evaluated in list context. </p>
  
  <p>An example is:</p>
  
  <pre><code>my $str = "5 and 4 and a 3 and 2 1 BLAST OFF!!!";
  my $count =()= $str =~ /\d/g; # 5 matches...
  print "There are $count numbers in your countdown...\n\n";
  </code></pre>
  
  <p>As I interprete the use, this is what happens:</p>
  
  <ol>
  <li><code>$str =~ /\d/g</code> matches all the digits. The <code>g</code> switch and list context produces a list of those matches. Let this be the "List Producer" example, and in Perl this could be many things.</li>
  <li>the <code>=()=</code> causes an assignment to an empty list, so all the actual matches are copied to an empty list.</li>
  <li>The assignment in scalar context to $count of the list produced in 2. gives the count of the list or the result of 5.</li>
  <li>The reference count of the empty list <code>=()=</code> goes to zero after the scalar assignment. The copy of the list elements is then deleted by Perl. </li>
  </ol>
  
  <p>The questions on efficiency are these:</p>
  
  <ol>
  <li>Am I wrong in how I am parsing this? </li>
  <li>If you have some List Producer and all you are interested in is the count, is there a more efficient way to do this? </li>
  </ol>
  
  <p>It works great with this trivial list, but what if the list was hundreds of thousands of matches? With this method you are producing a full copy of every match then deleting it just to count them.</p>