Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Regular expressions

by AnomalousMonk (Archbishop)
on Oct 27, 2015 at 07:27 UTC ( [id://1146069]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regular expressions
in thread Regular expressions

I would have organized the code slightly differently, factoring each of the pattern elements into a separate  qr// regex object and combining them together (inside a capture group) in the final  m// match:

c:\@Work\Perl\monks>perl -wMstrict -le "my $codon = qr{ [ACGT]{3} }xms; my $start = qr{ ATG }xms; my $end = qr{ TAG | TAA | TGA }xms; ;; my $seq = 'AATGGTTTCTCCCATCTCTCCATCGGCATAAAAATACAGAATGATCTAACGAA'; ;; print qq{'$1'} while $seq =~ m{ ($start $codon*? $end) }xmsg; " 'ATGGTTTCTCCCATCTCTCCATCGGCATAA' 'ATGATCTAA'
Separate  qr// definitions ease maintenance and, if variable names be wisely chosen, are self-commenting. If possible, I only use capture groups in the final  m// match due to the confusion that trying to count nested capture groups can produce.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found