[mplspm]: In a sorted list

patrickm patrickm at eltecinc.com
Fri Mar 22 09:19:30 CST 2002


my %seen = map { $_, 0 } @sorted_array;            # it doesn't have to be
sorted
if (exists $seen{bob}) {                                     # is string
'bob' in the array?
  print "yes\n";
} else {
  print "no\n";
}


----- Original Message -----
From: Josh Aas <josha at mac.com>
To: <mpls at pm.org>
Sent: Thursday, March 21, 2002 10:07 PM
Subject: [mplspm]: In a sorted list


> Hey MPM,
>     If I have an alphabetically sorted array of strings (containing up to
2
> million strings), and I want to find out if any strings in that array
equal
> a certain string (yes or no, not how many), what is the fastest way to do
> that search? This seems basic to me, I just can't come up with the answer
> and I have an hour to do so. Thanks a lot!
> -Josh
>
>
>
> --------------------------------------------------
> Minneapolis Perl Mongers mailing list
>
> To unsubscribe, send mail to majordomo at pm.org
> with "unsubscribe mpls" in the body of the message.



--------------------------------------------------
Minneapolis Perl Mongers mailing list

To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.



More information about the Mpls-pm mailing list