Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately Perl won't interpolate a variable into the search list for <code>tr///</code>. You will have to use a regular expression instead:</p> <pre><code>use strict; use warnings; my $orf = "ATGCTAGCTAGCATAGAGCTAGCTA"; my @atgc = qw(A T G C); my %count; $count{$1}++ while $orf =~ /([@atgc])/g; printf "%s =&gt; %d\n", $_, $count{$_} for @atgc; </code></pre> <p><strong>output</strong></p> <pre><code>A =&gt; 8 T =&gt; 6 G =&gt; 6 C =&gt; 5 </code></pre> <hr> <p><strong>Beware</strong></p> <p>This isn't - as it may appear - a general solution for matching any one of an array of strings. What is happening is <code>@atcg</code> is being interpolated into the regex as if it was in a <em>double-quoted string</em>. That means Perl will use the <code>$"</code> built-in variable (set to a single space by default) to turn it into a string equivalent to <code>join $", @atgc</code>.</p> <p>So the code actually looks like</p> <pre><code>$count{$1}++ while $orf =~ /([A T G C])/g; </code></pre> <p>which will match spaces as well as the letters, and may break altogether if <code>@atgc</code> contains anything that is special inside a regex character class like <code>^</code>, <code>]</code> or <code>-</code>.</p> <p>Counting spaces unnecessarily shouldn't be a problem, but if your list may contain symbols then this isn't a solution you should be using.</p> <p>A count for every ASCII character can be written safely as</p> <pre><code>$count{$1}++ while $orf =~ /(.)/sg; </code></pre> <p>and the unwanted information in the <code>%count</code> hash can simply be ignored.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload