Right! I have the same idea as you, and I have this :
my @list = ('1234', '4567', '789A', 'BCDE', 'FGHI');
my $GetLocation = 0;
my $value = 'BCDE';
for (my $atLoc = 0; $atLoc <= $#list and ! $GetLocation ; $atLoc++)
{ $GetLocation = $atLoc if ($value eq $list[$atLoc]) }
And I finally got the same ans. =)
Deal with it by a hash is the only choice....
Rgds,
Connie
----- Original Message -----
From: "Daniel David" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 25, 2002 6:00 PM
Subject: function for finding the index of an element in an array?
> Hi,
> I couldn't seem to find a built-in function for finding the index
> of an element in an array...so I wrote this one:
>
> --------------------------------------------------------------------
>
> # position_of returns the position of a string in an array of strings,
> # and -1 if the string is not a member of the array.
>
> sub position_of {
> my ($x,@y) = @_;
> foreach $z (0..$#y) {
> if (@y[$z] eq $x) {
> return ($z);
> }
> }
>
> return -1;
> }
> ----------------------------------------------------------------------
>
> it works.... but somehow i feel there's a built in function for this
>
> thanks.
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]