http://qs321.pair.com?node_id=841476

sesemin has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

How can I fix the following code (or may be rewrite) to print the keys and values of two hashes in a tabulated format. A simple operation also needed to be performed on values. The keys of two hashed are identical.

#! /usr/bin/perl -w use strict; my %hash_1 = ( 0.2 => '12', 0.4 => '13', 0.6 => '14', ); my %hash_2 = ( 0.2 => '19', 0.4 => '18', 0.6 => '20', ); foreach my $ObsKey ( sort { $a <=> $b } keys %hash_1 ) { foreach my $PermKey ( sort { $a <=> $b } keys %hash_2 ) { my $diff_obs_perm = $hash_1{$ObsKey}-$hash_2{$PermKey}; my $FDR = $hash_2{$PermKey} / $hash_1{$ObsKey}; my $currentdeltaprint = join ("\t", $ObsKey, $hash_1{$ObsKey}, $hash_2{$PermKey}, $diff_obs_perm, $FDR ); print "$currentdeltaprint\n"; } }

It seems I need to exit the inner loop after each printing. But it keeps printing until all the keys of the inner loop get exhausted and goes to the outer loop.

Thanks Monks.