in reply to Hash key intersection
How about:
foreach ( keys %hash1 ) { my $out = ( exists $hash2{$_} ) ? $hash1{$_} . "." . $hash2{$_} : $hash1{$_} ; print $out, "\n"; }
This assumes that if a key exists its value is defined. It also assumes that what you really meant was that you want to print the value associated with the keys in the respective hashes.
I hope I haven't robbed you of your opportunity for an education. ;) See perldata, exists, keys, perlsyn, and perlop for an understanding at the mechanisms at work in this snippet. If your professor hasn't discussed the ternary operator yet, you may need to be able to explain how you know about it and how to use it. That's found in perlop.
Dave
|
|---|