Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: How to get the correct count

by eyepopslikeamosquito (Chancellor)
on Apr 19, 2012 at 11:48 UTC ( #965928=note: print w/replies, xml ) Need Help??


in reply to Re: How to get the correct count
in thread How to get the correct count

I endorse all the excellent improvements made by GrandFather. Some further minor tweaks follow. For removing whitespace, you could change from:

$seq =~ s/\s//g;
to:
$seq =~ s/\s+//g;
That should be a touch more efficient and is more idiomatic -- see also perlfaq4 "How do I strip blank space from the beginning/end of a string?".

An alternative for counting the number of bases is to change from:

my $A = () = $seq =~ /A/ig;
to:
my $A = $seq =~ tr/aA//;
Counting characters with tr seems a bit odd but is normally fastest and is idiomatic Perl -- see Quote and Quote-like Operators.

Finally, to see what actually matches in the regex, and so help you debug it, note that you could expand it a bit like this:

my @matches = $seq =~ /[AG]TG.*?T[AG][AG]/ig; print "Here are the matched parts of the string:\n"; print " '$_'\n" for @matches; my $GENE = @matches;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965928]
help
Chatterbox?
[james28909]: ok maybe i need to ask this question in sopw and not CB but here goes
[james28909]: i am manually parsing html, and am trying to wrap my head around keeping up with tag counts

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-04-25 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (448 votes). Check out past polls.