Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

Hi Shawn,

Thank you very much,

Shown from your code below and my print1 and prin2 comments below:

print1 correctly prints the following:

emcpoweraa sdae sdch sdek sdgn /dwpdb033
emcpowerd sdba sddd sdfg sdhj /odsdb005
emcpowerc sdbb sdde sdfh sdhk /odsdb006
emcpowerbc sdb sdbe sddh sdfk /s00_11
emcpowerbc sdb sdbe sddh sdfk /utl_file_dir
emcpowera sdbd sddg sdfj sdhm /dwpdb006

print2 incorrectly prints the following:

emcpoweraa sdae sdch sdek sdgn
emcpowerd sdba sddd sdfg sdhj
emcpowerc sdbb sdde sdfh sdhk
emcpowerbc sdb sdbe sddh sdfk
emcpowera sdbd sddg sdfj sdhm

Print2 should only print this line:
emcpowerz" => "sdba sddd sdfg sdhj

my( %hash3, %nothash );
my $found = 0;
while( my( $ikey, $ival ) = each( %hash1 ) ) {
while( my( $jkey, $jval ) = each( %hash2 ) ) {
(my $mkey = $jkey ) =~ s/[0-9]//g;
if( $ikey eq $mkey ) {
$hash3{ $ikey } = $ival . " " . $jval;
$found = 1;
print "$ikey $ival $jval\n"; # <-------------------- print1
}
}
if( $found == 1 ) {
$nothash{ $ikey } = $ival;
$found = 0;
print "$ikey $ival\n"; # <------------------------------ print2
}
}

Many thanks for your help!

Wernher

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Wernher Eksteen [ So, 03 April 2011 21:37 ] [ ID #2057583 ]
Perl » gmane.comp.lang.perl.beginners » Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

Vorheriges Thema: recursive ref value match
Nächstes Thema: Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3