Michael Alipio wrote:
> Hi,
>
>> - Original Message From: Igor Sutton <[EMAIL PROTECTED]> To:
>> Mumia W. <[EMAIL PROTECTED]> Cc: Beginners List
>> Sent: Friday, January 19, 2007 4:42:09 PM Subject: Re:
>> Searching hash if a given value exist
Hi,
> - Original Message
> From: Igor Sutton <[EMAIL PROTECTED]>
> To: Mumia W. <[EMAIL PROTECTED]>
> Cc: Beginners List
> Sent: Friday, January 19, 2007 4:42:09 PM
> Subject: Re: Searching hash if a given value exists
> [...]
&g
"Igor Sutton" schreef:
> [attribution repaired] Mumia W:
>> Yes there is a faster way. Use the "reverse" function:
>>
>> my %hash = (dog => 'house', pig => 'barn', bird=> 'cage');
>> my %rhash = reverse %hash;
>> if ($rhash{house}) {
>> print "Found house.\n";
>> }
>
>
[...]
New benchmarks about the subject:
foreach_hash_keys: 4 wallclock secs ( 4.40 usr + 0.00 sys = 4.40
CPU) @ 227272.73/s (n=100)
foreach_hash_values: 4 wallclock secs ( 3.46 usr + 0.01 sys = 3.47
CPU) @ 288184.44/s (n=100)
reverse_hash: 6 wallclock secs ( 6.85 usr + 0.01 sys =
Yes there is a faster way. Use the "reverse" function:
my %hash = (dog => 'house', pig => 'barn', bird=> 'cage');
my %rhash = reverse %hash;
if ($rhash{house}) {
print "Found house.\n";
}
That's a really good looking idiom, but I see it is less efficient
than the fo
On 01/18/2007 07:46 PM, Michael Alipio wrote:
Hi,
Suppose I have a hash:
my %hash = (dog => 'house', pig => 'barn', bird=> 'cage');
Now I want to know if there is already a key with a 'house' value as I do not
want to create another key with the same value.
Is there any other faster way to do
Michael Alipio wrote:
Hi,
Suppose I have a hash:
my %hash = (dog => 'house', pig => 'barn', bird=> 'cage');
Now I want to know if there is already a key with a 'house' value as I do not
want to create another key with the same value. Is there any other faster way
to do it than doing a
for (ke
2007 9:53:49 AM
Subject: Re: Searching hash if a given value exists
Hi Michael,
> To answer your questions, If you want to know if there is already a
> key with a certain value, you have to look through the entire hash.
> However if you want to see if a given key exists, just do "i
- Original Message
From: Jason Roth <[EMAIL PROTECTED]>
To: Michael Alipio <[EMAIL PROTECTED]>
Cc: begginers perl.org
Sent: Friday, January 19, 2007 9:53:49 AM
Subject: Re: Searching hash if a given value exists
Hi Michael,
> To answer your questions, If you want to k
Hi Michael,
To answer your questions, If you want to know if there is already a
key with a certain value, you have to look through the entire hash.
However if you want to see if a given key exists, just do "if (exists
$hash{$key})". This will take constant time regardless of the number
of elemen
10 matches
Mail list logo