l.frankline has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I am trying to find out the index value of a specific element in an array. I have tried below code and it is working fine,
but it doesn't seems to be pretty well, because the code contains too many lines.
Is there any shortest and easiest way.
@roman = qw(i ii iii iv v vi vii viii ix x xi xii xiii xiv xv xvi xvii + xviii xix xx); $indx=0; for (@roman) { $indx++; print "Index value for $_ is: $indx" if ($_ eq 'xiv'); }
Results:
Index value for xiv is: 14Thanks in advance
Regards,
Franklin.
Don't put off till tomorrow, what you can do today.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find Index value of a specific element in an array
by bobf (Monsignor) on Jan 03, 2006 at 06:16 UTC | |
|
Re: Find Index value of a specific element in an array
by Samy_rio (Vicar) on Jan 03, 2006 at 06:01 UTC | |
|
Re: Find Index value of a specific element in an array
by grinder (Bishop) on Jan 03, 2006 at 10:49 UTC | |
|
Re: Find Index value of a specific element in an array
by holli (Abbot) on Jan 03, 2006 at 10:43 UTC |