in reply to hash question

One solution is going through all the keys of one the hashes and check if those are defined on the second one.
foreach my $key (keys %csahash) { if(defined $cathhash{$key}) { print "$key matches. It's values are $csahash{$key} and $cathh +ash{$key}\n"; } }

update
having written a foreach, thought it would be a good candidate for a 'map' solution.
map { print "$_ matches. It's values are $csahash{$_} and $cathhash{$_ +}\n" if(defined $cathhash{$_}) } keys %csahash;
update 2
updated the map solution by adding, the mistakingly droped, 'defined' to the if clause.
Thanks johngg for pointing that out.

Replies are listed 'Best First'.
Re^2: hash question
by johngg (Canon) on Dec 11, 2007 at 12:41 UTC
    Re. your map solution, I think it might be safer to test for the existence of a key in case the value is 0 or the empty string. Also grep could come into play.

    print map { qq{$_ matches. It's values are $csahash{$_} and $cathhash{$_ +}\n} } grep { exists $cathhash{$_} } keys %csahash;

    I hope this is of interest.

    Cheers,

    JohnGG