#!/usr/bin/perl

#More Explanatory Way
$hash{'jmj'} = ['john','doe','laura','george','bill','nelson'];
for $ele ( @{$hash{'jmj'}} )
{
        if( $ele eq 'george' )
        {
              print "Take working Vacation Bud!\n";
        }
}

#Mode Idiomatic Way and is more efficient too!
map { print "Take working vacation bud\n"; } grep{$_ eq 'george'}
@{$hash{'jmj'}};

I would prefer the second way -- the idiomatic way of doing it in Perl. I
have read, somewhere that the second approach is more efficient. 
 
-- Rex
 
-----Original Message-----
From: Luke Bakken [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ]
Sent: Tuesday, August 07, 2001 3:59 PM
To: Sophia Corwell
Cc: [EMAIL PROTECTED]
Subject: Re: Hashes with multiple values per key


> Does anyone have any ideas on what is a good way to
> check the existance of a value for a key that has
> multiple values?

I'll assume that your hash table has the following structure:

$hash{$key} = [ ];

that is, the value of each hash element is an array reference.

Let's say you're looking for element "frazzle" in the key represented by
variable $key :

for $ele ( @{$hash{$key}} )
{
        if( $ele eq 'frazzle' )
        {
              print "YEAH\n";
        }
}

Luke




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

Reply via email to