Mallik wrote:
I need to find the index of a particular element in array.
For eg.,
@arr = ('abc', 'xyz', 'mno','pqr','stu','sdfd');
I want to find the index of the element 'pqr' which is 4.
Any function/code to achieve this.
for my $i ( 0 .. $#arr ) {
if ( $arr[ $i ] eq 'pqr' ) {
$index = $i;
last;
}
}
Or if all the elements of @arr are unique:
my %hash;
@hash{ @arr } = 0 .. $#arr;
my $index = $hash{ pqr };
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>