If I get you correctly the %supliers hash will look like this in this
script:
%supliers =(booboo =>'1',
Puter =>'1',
Synta => 'defined')
... or am I wrong. I need to see the real print of this hash in order to
understand it...
Thanx a lot!
R o n e n K f i r
System Administrator
CIT div. Tel Aviv University
Israel
Tel: 972-3-6407416
Fax: 972-3-6405158
cellular: 972-55-405910
E-mail: [EMAIL PROTECTED]
-----Original Message-----
From: Jan Eden [mailto:[EMAIL PROTECTED]
Sent: Friday, February 13, 2004 4:39 PM
To: Ronen Kfir; Perl Lists
Subject: RE: basic explanation on code
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>