Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: getting a sequence of numbers and leters

by choroba (Archbishop)
on Mar 23, 2020 at 17:48 UTC ( #11114572=note: print w/replies, xml ) Need Help??

in reply to getting a sequence of numbers and leters

It should be doable using a single regex:
#!/usr/bin/perl use warnings; use strict; my $line = "BOGUS PPI3_SYNY3 276 aa linear BCT 13-NOV-2019\n"; if (my ($bogus, $acids) = $line =~ /BOGUS\s+([A-Z0-9_]+) ([0-9]+ [a-z] ++)/) { print "bogus: $bogus\nNumber of acids: $acids\n" }

Your code is unfortunately incomplete. How did you populate $noOfAcids? Also, $ in the second regex can't match after "aa", as the string doesn't end there. Note that $1 et al. are only changed after a successful match, so if the second regex doesn't match, the value of $1 keeps the value from the previous match.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-05-30 06:32 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (171 votes). Check out past polls.