Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Find element in array

by LanX (Cardinal)
on Feb 16, 2020 at 12:43 UTC ( #11113021=note: print w/replies, xml ) Need Help??

in reply to Find element in array

Do you mean the current index of @DNA when looping?


The traditional way with your code is to use an explicit counter:

my $idx=-1; for my $nucleotide (@DNA){ $idx++; ... }

But you can also apply while / each on arrays

while ( my ($idx, $nucleotide) = each @DNA){ ... }

(I tapped this message into a mobile, no guaranty for the code.)

HTH! :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Find element in array
by Sofie (Acolyte) on Feb 16, 2020 at 13:25 UTC

    es the current index of the @DNA. I want to have a warning for each position of an element in the array that contains an invalid character. And then count the number of invalid characters.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2020-07-12 20:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found