Johnson, Reginald (GTS) wrote:
I am wondering if I am doing this in an efficient manor. I am taking my
first input file and putting it in a hash with server name as a the key.
The second input file has two fields exp_server and exp_date. I put
this file in hash using exp_server as the key. I then check if
exp_server exist in the first hash. If it does I out put the first hash
with the exp_date value. For keys where exp_server doesn't exist I out
put the first hash and "---" for the value of exp_date.
$ cat combine_exprman_perl
#!/usr/bin/perl
use strict;
use warnings;
my $today;
$today=`/usr/bin/date +%m%d%Y`;
chomp $today;
open (RMANFILE,"<","/adsm/ACTIVITIES/ANR4391I/rman_out-$today")
or
die "RMANFILE could not be opened :$!\n";
my
($server,$db,$obj,$oldate,$tb,$dont_need,$past,$bkupserv,$lastbkup);
my %rman_Hash=();
while (<RMANFILE>) {
($server,$db,$obj,$oldate,$tb,$dont_need,$past,$bkupserv,$lastbkup) =
split(/ +/,$_);
$rman_Hash{$server}{'db'} = $db;
$rman_Hash{$server}{'obj'} = $obj;
$rman_Hash{$server}{'oldate'} = $oldate;
$rman_Hash{$server}{'tb'} = $tb;
$rman_Hash{$server}{'past'} = $past;
$rman_Hash{$server}{'bkupserv'} = $bkupserv;
$rman_Hash{$server}{'lastbkup'} = $lastbkup;
} #end while
my($key, $value);
open(EXPFILE,"<","/adsm/ACTIVITIES/ANR4391I/expfile") or
die "Could not open EXPFILE :$!\n";
my($exp_serv,%exp_Hash);
while (<EXPFILE>) {
my($exp_servname,$exp_date)= split(/ /,$_);
($exp_serv)= split(/_ORA/,$exp_servname);
chomp($exp_date);
$exp_Hash{$exp_serv}{'exp_date'} = $exp_date;
} #
my (%output_Hash,$dash);
$dash="---";
foreach $key (keys %exp_Hash) {
if (exists $rman_Hash{$key}) {
$rman_Hash{$key}{'exp_date'} =
$exp_Hash{$key}->{'exp_date'};
$output_Hash{$key}{'db'} =
$rman_Hash{$key}->{'db'};
$output_Hash{$key}{'obj'} =
$rman_Hash{$key}->{'obj'};
$output_Hash{$key}{'oldate'} =
$rman_Hash{$key}->{'oldate'};
$output_Hash{$key}{'tb'} =
$rman_Hash{$key}->{'tb'};
$output_Hash{$key}{'past'} =
$rman_Hash{$key}->{'past'};
$output_Hash{$key}{'bkupserv'} =
$rman_Hash{$key}->{'bkupserv'};
$output_Hash{$key}{'lastbkup'} =
$rman_Hash{$key}->{'lastbkup'};
$output_Hash{$key}{'exp_date'} =
$exp_Hash{$key}->{'exp_date'};
} #end if
}#end foreach
foreach $key (keys %rman_Hash) {
if (! exists $output_Hash{$key}) {
$output_Hash{$key}{'db'} =
$rman_Hash{$key}->{'db'};
$output_Hash{$key}{'obj'} =
$rman_Hash{$key}->{'obj'};
$output_Hash{$key}{'oldate'} =
$rman_Hash{$key}->{'oldate'};
$output_Hash{$key}{'tb'} =
$rman_Hash{$key}->{'tb'};
$output_Hash{$key}{'past'} =
$rman_Hash{$key}->{'past'};
$output_Hash{$key}{'bkupserv'} =
$rman_Hash{$key}->{'bkupserv'};
$output_Hash{$key}{'lastbkup'} =
$rman_Hash{$key}->{'lastbkup'};
$output_Hash{$key}{'exp_date'} = $dash;
} #end if
} #end foreach
foreach $key (keys %output_Hash) {
print "$key ";
print " $output_Hash{$key}->{'db'} ";
print " $output_Hash{$key}->{'obj'} ";
print " $output_Hash{$key}->{'oldate'} ";
print " $output_Hash{$key}->{'tb'} ";
print " $output_Hash{$key}->{'past'} ";
print " $output_Hash{$key}->{'bkupserv'} ";
print " $output_Hash{$key}->{'lastbkup'} ";
print " $output_Hash{$key}->{'exp_date'}\n";
} #end foreach
close(RMANFILE);
close(EXPFILE);
It looks like you may want something more like this (*UNTESTED*):
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/strftime/;
my $today = strftime '%m%d%Y', localtime;
open RMANFILE, '<', "/adsm/ACTIVITIES/ANR4391I/rman_out-$today" or die
"RMANFILE could not be opened :$!\n";
my %output_Hash;
while ( <RMANFILE> ) {
my ( $server, @fields ) = ( split / +/ )[ 0, 1 .. 4, 6 .. 8 ];
@{ $output_Hash{ $server } }{ qw/db obj oldate tb past bkupserv
lastbkup/ } = @fields;
}
close RMANFILE;
open EXPFILE, '<', '/adsm/ACTIVITIES/ANR4391I/expfile' or die "Could not
open EXPFILE :$!\n";
while ( <EXPFILE> ) {
my ( $exp_servname, $exp_date ) = split;
my ( $exp_serv ) = split /_ORA/, $exp_servname;
$output_Hash{ $key }{ exp_date } = exists $output_Hash{ $key } ?
$exp_date : '---';
}
close EXPFILE;
for my $key ( keys %output_Hash ) {
print "$key @{$output_Hash{$key}}{qw/db obj oldate tb past bkupserv
lastbkup exp_date/}\n";
}
__END__
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/