There's no built-in that I know of that does this, but
this is one way:
#! /usr/local/bin/perl -w
use strict;
my @array = qw(Jim Jack Jerry Jeff Joe);
my $to_find = 'Jeff';
my $index=get_el_index($to_find, @array);
print "Index of [$to_find] is [$index]\n";
sub get_el_index($@) {
my $el = shift;
$_ eq $el && return @_ while $_ = pop;
-1;
}
HTH
Jeff D.
--- [EMAIL PROTECTED] wrote:
> Okay, I know a hash would do this, but I'm mostly
> just curious...
>
> Is there some way to extract the index of an array
> element? For instance:
>
> @array = ( "Ben", "George", "Thomas", "Mervyn",
> "Alexander" );
>
> $idx = some_op @array "Mervyn";
>
> print "The index of Mervyn in the array is $idx!\n";
>
> # The index of Mervyn in the array is 3!
>
> What, if anything, might "some_op" be?
>
> Thanks,
>
> Deane>
_______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> To unsubscribe:
http://listserv.ActiveState.com/mailman/mysubs
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs