Got this to work, but is there a better way to do this?
#!/usr/bin/perl
use strict;
use warnings;
my ( $val, @matched, @unmatched, %hash1, %hash2 );
%hash1 = (
"emcpowera" => "sdbd sddg sdfj sdhm",
"emcpoweraa" => "sdae sdch sdek sdgn",
"emcpowerbc" => "sdb sdbe sddh sdfk",
"emcpowerc" => "sdbb sdde sdfh sdhk",
"emcpowerd" => "sdba sddd sdfg sdhj",
"emcpowerz" => "sdba sddd sdfg sdhj"
);
%hash2 = (
"emcpowera1" => "/dwpdb006",
"emcpoweraa1" => "/dwpdb033",
"emcpowerbc1" => "/s00_11",
"emcpowerbc2" => "/utl_file_dir",
"emcpowerc1" => "/odsdb006",
"emcpowerd1" => "/odsdb005"
);
foreach my $i (keys(%hash1)) {
foreach my $b (keys(%hash2)) {
if ($b =~ /$i[0-9]+/) {
$val = $b;
push @matched, "$i" . " $hash1{$i} " . "$b" . "
$hash2{$b} " . "\n";
}
}
if (not $i =~ /$val*/) {
push @unmatched, "$i" . " $hash1{$i} " . "\n";
}
}
print " @matched";
print " @unmatched\n";
--- RESULT ---
emcpoweraa sdae sdch sdek sdgn emcpoweraa1 /dwpdb033
emcpowerd sdba sddd sdfg sdhj emcpowerd1 /odsdb005
emcpowerc sdbb sdde sdfh sdhk emcpowerc1 /odsdb006
emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
emcpowerbc sdb sdbe sddh sdfk emcpowerbc2 /utl_file_dir
emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006
emcpowerz sdba sddd sdfg sdhj
--
Regards.
Wernher
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/