Will this be sufficient?

my($array) = ['a=1', 'b=2', 'c=3', 'd=4'];
my($str) = 'd=43';
my($index) = indexOf($array,$str);
print ("Index of $str in the array is = $index");

sub indexOf{
 my($arr) = shift;
 my($val) = shift;
 for(my $i=0; $i < @{$arr}; $i++){
  return($i) if($arr->[$i] eq $val);
 }
 return("undef"); #WE should not get here if a match is found
}


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 03, 2001 7:45 AM
Subject: index of an array element


>
>
> Hi ,
>
> Say I have an array in perl,
>
> @list = ("a=3", "b=5", "c=8", "d=9", "e=2", "f=0");
>
> Now I want to find the index of the element "d=9" ( Index of d=9 is 3 here
, as
> we all know ).
>
> How do we do that ??
>
> In perl what I can find that there exist a function "index", which returns
> position of the substring in string..........like,
>
> $c = index(@list, "d" );
>
> This function will return me the value 13 or 12 perhaps....as the
substring
> "d=9" begins from 13th position in the @list.
>
> My requirment is :
>
> $c = some_func(@list, "d"); .............where some_func should return me
> 3......... Can anybody help me.
>
> TIA,
> -Mini.
>
>
>
> --
> 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]

Reply via email to