[Charlotte.PM] find index of array element

diona kidd diona at studio12a.com
Tue Mar 22 07:02:46 PST 2005


Ok, I thought I'd start a discussion here before posting this to
perlmonks. I have a little perl task that I often do and just as often
forget how to do. I seem to recall doing it before with grep, map, or
some combination. dunno....when I find out again, I'm going to post it
on my site for reference. 

say you have an array and you want to find the index of a particular
element by string comparison. You can do a foreach loop but I know
there's a cleaner way...

my @array = qw( item1 item2 item3 item4 );

find the index of item3. 

anyone?



More information about the charlotte mailing list