Re: Compare values of two or more arrays
[email protected] (Rob Dixon)
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
Mimi Cafe wrote:
> Hi Rob,
>
> The scope of the hash was the cause of the wrong behaviour. I have
> modified the script as you indicated and it now generate per-file report
> correctly.
>
> What is unclear is the way you added hash values by incrementing it. What
> happens here?
>
> $inputclient{$_}++;
(Please make posts to the perl.beginners group unless they must be private for
some reason. That way others will be able to learn, as well as correct our
mistakes. Thanks.)
I'm glad it worked.
$hash{$key}++;
just increments the value of the hash element indexed by key. It's a useful
idiom in the case you were writing for as it lets you test for
if ( exists $hash{$key} )
or just
if ( $hash{$key} )
as well as keeping count of the number of times $key has been seen, just in case
it may be useful for debugging.
Rob