Hi,

Ronen Kfir wrote:

>Hi Jan,
>I am sorry...
>
>This is the right code:
>
>
>#!/usr/bin/perl
>
>%machines =(user1, 'booboo',
>            user2, 'puter',
>       user3, 'synta',
>            user4, 'synta');
>
> for (keys %machines)
> {
>    $val=$machines{$_};
>       if (!defined $supliers{$val})
>      {
>         $supliers{$val}=1;
>       #  print "hi\n";
>    }
>    else
>    {
>        print "duplicate value: $val\n";
>        
>    }
> }   
>
>Seems more reasonable now... What I cant comprehend now is the
>$supliers{$val part. What's inside it , &  all the mechanism around
>its action.
>

The %supliers hash must have keys which equal the values of the %machines hash. So the 
hashes are "tied together" in a way.

The way this is written, the %supliers keys will be booboo, puter and synta. For each 
of these suppliers, you check if it's value is defined. The idea is to mark the 
supplier synta as duplicate: when you use the value of $machines{user3}, you assign 1 
to $supliers{synta}. On a subsequent looping, $supliers{synta} will be defined, so you 
get the duplicate message.

Best,

Jan
-- 
If all else fails read the instructions. - Donald Knuth

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to