Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: searching characters

by Transient (Hermit)
on Jun 17, 2009 at 14:37 UTC ( #772415=note: print w/replies, xml ) Need Help??


in reply to searching characters

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2020-07-07 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?