Hi,
Ronen Kfir wrote:
>#!/usr/bin/perl
>
>
>%machines =(user1, 'booboo',
> user2, 'puter',
> user3, 'synta',
> user4, 'synta');
>
> for $key (keys %machines)
> {
> $val=$programs{$key}
> if (!defined $supliers{$val})
> {
> $supliers{$val}=1;
> }
> else
> {
> print "duplicate value: $val\n";
> print "duplicate value: $val\n";
>
>Cannot understand what is the purpose of $key (keys %machines) ,
>$programs{$key} and $supliers{$val} on this script.
�keys %machines" returns a list of the keys of the %machines hash, in this case
(user1, user 2, user3, user4)
There are two other hashes, %programs and %supliers. Obviously, %pograms should have
the same set of keys as %machines.
Now, the for loop assigns the value of $programs{$key} to $val and checks of there is
a value defined for $supliers{$val}. If that is the case, it prints the message
""duplicate value..." twice (funny idea), otherwise it assigns 1 to $supliers{$val}.
Now if you run this two or more times, you should always get the duplicate value
message since you defined each $suplier{$val} on the first run.
- Jan
--
There's no place like ~/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>