[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Re. Associative arrays in perl

> 2. How do i check for redundant key values while creating the array?
> I din't quite follow what u mean.
> What i meant was, when i am creating  an associative array, how do i check
> for keys that already exist?


print "Key already present " if exists $hash{$key};
It is not necessary that the key has a value when it is presnet.

print "The value is defined" if defined $hash{$key};

> Will perl ignore the new value or will it over
> write the new value with the old, for the same key?

Yes if you try to assign a new value, Perl will overwrite the old.

> Thanks in advance,
> Adityan