[EMAIL PROTECTED] wrote:

> For key-value pair type of lists, hashes are the way to go. I had shown the
> other way using a list, which does not need the 'key-value' caveat.
>
> However for your case, Mini, you need to tread the hash path as shown by
> Sudarshan.
>
> Here is a code snippet you can try.
>
> #!/usr/bin/perl
>
> my($hash) = {a=>1, b=>2, c=>3, d=>4};
> my($key) = 'b';
> my($index) = indexOf($hash,$key);
> print ("Index of $key in the hash is = $index");
>
> sub indexOf{
>  my($myHash) = shift;
>  my($val) = shift;
>  if(exists $myHash->{$val}){
>          return $myHash->{$val} ;

     You are returning the value associated with the key $val here, not the
index.
     This can be directly accessed from the hash without having to call a
subroutine.


>
>  }
>  else{
>         return("undef"); #WE should not get here if a match is found
>  }
> }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to