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.