You could also do something like:
sub mylineOK {
my ($line) = @_;
my @ebase = ("A","T");
my $limit = 15;
for ( @ebase ) {
my $cnt = ( $line =~ s/$_//g );
return 0 if ( $cnt >= $limit );
}
return 1;
}
Which will just count the number of times the ebase is stripped from the line.
Update:
All of these return the correct answer (in my very limited dataset). Here are some benchmarks.
Rate Original Moritz Tr m Strip
+ExplicitTr
Original 87.3/s -- -95% -97% -99% -99%
+ -100%
Moritz 1613/s 1748% -- -50% -74% -81%
+ -98%
Tr 3226/s 3596% 100% -- -48% -62%
+ -96%
m 6250/s 7060% 288% 94% -- -27%
+ -92%
Strip 8571/s 9720% 431% 166% 37% --
+ -89%
ExplicitTr 75000/s 85825% 4550% 2225% 1100% 775%
+ --
Note that explicit tr uses a hardcoded "A" and "T" in place of a variable.
(i.e. tr/A/A/ and tr/T/T/) The eval is what kills the performance.
-
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.
|