more useful options | |
PerlMonks |
Re: Find last position of an element in arrayby davido (Cardinal) |
on Mar 28, 2022 at 21:04 UTC ( [id://11142470]=note: print w/replies, xml ) | Need Help?? |
List::Util is a core Perl module (ships with Perl) and provides a subroutine called first. That subroutine returns the actual element. But if you treat indexes as elements and reverse them you can get what you need:
If non-Core modules are allowed, which they ought to be, you can use List::MoreUtils, which provides lastidx, in which case you could do this:
If you don't want to use a module, just do this:
And then repent for not being willing to use a module (even though this is quite easy to solve without). Dave
In Section
Seekers of Perl Wisdom
|
|