in reply to Find last position of an element in array

TIMTOWTDI

one possibility is to loop backwards, $array[-1] gives you the last element and so on.

please note that this is illegal incorrect syntax

> $array=(1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4,4,5,5,6);

you most probably meant

@array=(1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4,4,5,5,6);

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

Replies are listed 'Best First'.
Re^2: Find last position of an element in array
by hippo (Archbishop) on Mar 28, 2022 at 18:06 UTC
    please note that this is illegal syntax

    "Illegal" is a bit strong. It is perfectly valid syntax, compiles fine and evaluates the list in scalar context. That's just not what the OP was after in this case.


    🦛