On Wed, Oct 03, 2001 at 07:09:36PM +0530, [EMAIL PROTECTED] wrote:
> I am not using hashes for the same reason described by Rex, i.e.. My list might
> not a key=value pair everytime. The list could be for example
> ("GMM_ASSIGN_REQ", "TLLI=0x123456", "TLLI_INDEX=00", "LLC_PDU=$pdu);
>
> Here , th
In a later mail the OP has mentioned that her list may be of the form
my @ops_list = ("a", "b=7", "c=8");
The first element does not have a "=" in it. I am assuming that the key that
she uses for search here is "a".
Your code snippet will return an undef when called with some_func (@ops_list,
"a")
found
}
-- Rex
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 03, 2001 9:40 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: RE: index of an array element
I am not using hashes for the same reas
as key value pair.
Regards,
-Mini.
[EMAIL PROTECTED] on 10/03/2001 06:31:15 PM
To: [EMAIL PROTECTED], Mini Dwivedi/HSS@HSS
cc: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: RE: index of an array element
For key-value pair type of lists, hashes are the way to go. I had shown the
other way us
[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
return("undef"); #WE should not get here if a match is found
}
}
- Rex
-Original Message-
From: Sudarsan Raghavan [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 03, 2001 8:59 AM
To: [EMAIL PROTECTED]
Cc: Rex Arul; [EMAIL PROTECTED]
Subject: Re: index of an array el
gt;
> "Rex Arul" <[EMAIL PROTECTED]> on 10/03/2001 06:02:30 PM
>
> To: "Sudarsan Raghavan" <[EMAIL PROTECTED]>, Mini Dwivedi/HSS@HSS
> cc: [EMAIL PROTECTED]
>
> Subject: Re: index of an array element
>
> But that would work only for key=v
IL PROTECTED]>, Mini Dwivedi/HSS@HSS
cc: [EMAIL PROTECTED]
Subject: Re: index of an array element
But that would work only for key=value type of situations.
If @list = (2,'a',100,'cat')
then you cannot rely on Hashes because order cannot be preserved. At such
instan
ces, you might need to code a custom function as shown in my previous
> mail.
>
> Right?
>
> -- Rex
>
> - Original Message -
> From: "Sudarsan Raghavan" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
&g
l Message -
From: "Sudarsan Raghavan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, October 03, 2001 8:18 AM
Subject: Re: index of an array element
> [EMAIL PROTECTED] wrote:
>
> > Hi ,
> >
> > Say I
[EMAIL PROTECTED] wrote:
> Hi ,
>
> Say I have an array in perl,
>
> @list = ("a=3", "b=5", "c=8", "d=9", "e=2", "f=0");
looking at your list a hash seems like a better option, the hash will be like
%hashlist = (
a => 3,
b => 5,
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);
12 matches
Mail list logo