Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl noob struggling to loop through an array

by aitap (Deacon)
on Oct 24, 2012 at 15:52 UTC ( #1000661=note: print w/replies, xml ) Need Help??


in reply to Perl noob struggling to loop through an array

Greetings, Microkorg.

The file I have read into the array is a .fasta DNA sequence file
Search for "fasta" gives many results, and nearly all threads contain links to already written code for FASTA manipulation: BioPerl http://bioperl.org fasta allBio::AlignIO::fasta

Your code is OK, but please don't use $& because it can slow down your other regexps. Catch symbols using (regexp) and use them as $number_of_catch_group, like this:

if ($line =~ /^>(.+)$/ ) { $header = $1; }
WARNING: Once Perl sees that you need one of $&, "$`", or "$'" anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression "(?: ... )" instead.) But if you never use $&, "$`" or "$'", then patterns without capturing parentheses will not be penalized. So avoid $&, "$'", and "$`" if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two.
Seen at perlre, right before Quoting metacharacters.

Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000661]
help
Chatterbox?
[marioroy]: Is List::Util::XS a core Perl module?
[stevieb]: corelist List::Util::XS says "List::Util::XS was first released with perl v5.10.1"
[stevieb]: so yes, since v5.10.1 :)
[MidLifeXis]: According to [metaperl:// corelist], Perl 5.10.1
Lady_Aleena blurbles. One of her favorite modiles is now in "maintenance mode" in favor of a new fangled module.
[MidLifeXis]: D'oh. Slow out of the gate.
[marioroy]: Thanks stevieb, MidLifeXis.
[MidLifeXis]: corelist Typo. Wow. Time to go, fingers are malfunctioning.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-05-24 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?