Wasn't really clear what I was trying to accomplish. Basically I am trying to iterate through 2 hashes at the same time so I can print 1 key / value pair from each hash on the same line. Repeating through each hash. Making things more complicated I am forced to use perl4 with no libraries, so I can't use any of the nifty modules from cpan etc. I've tried to get the sysad's here to upgrade, but it seems it will take an act of congress to get them to upgrade these archaic systems. Here's the whole script and some output that is produced, truncated (full file is about 3000 lines). Script takes reports from our repository with file names and the current version that is supposed to be fielded, and a report with the filenames and version of what is actually on the live server. Validating the server.
#!/usr/contrib/bin/perl $CPROD, $CTARGET, $CVALID, $CINVAL = 0; open (PROD, "@ARGV[0]"); %PROD = ("file", "version"); while (<PROD>){ unless (grep(/^Change|^\n/,$_)){ ($FILE, $VER) = ($_ =~ m/(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)/); ($FILE = substr($FILE,rindex($FILE,"\\")+1)) =~ y/A-Z/a-z/; $PROD{$FILE} = $VER; } $CPROD++; } close PROD; open (TARGET, "@ARGV[1]"); %TARGET = ("file", "version"); %PKG = ("file", "package"); while (<TARGET>){ unless (grep(/^NAME|^\-|^\s|selected\.$|^Input|^\n/,$_)){ ($PACKAGE, $FILE, $VER) = ($_ =~ m/(\S+)\s+(\S+)\s+(\S+)/); ($FILE = substr($FILE,rindex($FILE,"\/")+1)) =~ y/A-Z/a-z/; $TARGET{$FILE} = $VER; $PKG{$FILE} = $PACKAGE; $CTARGET++; } } close TARGET; #if (@ARGV[2]){ # open (VIEWS, "@ARGV[2]"); # %VIEWS = ("file", "version"); # while (<VIEWS>){ # if (grep(/^\/\*/,$_)){ # unless (grep(/^\/\*\+/,$_)){ # ($_ = substr($_,(index($_,"L")))) =~ s/\s+$/\n/; # ($FILE, $VER) = ($_ =~ m/(\S+)\s+(\S+)/); # ($FILE = substr($FILE,rindex($FILE,"\/")+1)) =~ y/A-Z/a-z/; # $PROD{$FILE} = $VER; # } # } # } # close VIEWS; #} open (OUT, ">valid.out"); foreach (sort keys (%PROD)){ unless ($_ eq "file"){ $FILE = $_; $VER = $PROD{$_}; # print OUT "Checking for $FILE version $VER\n"; foreach (sort keys (%TARGET)){ if ($_ eq $FILE){ if ($VER eq $TARGET{$_}){ unless ($_ eq "file"){ # print OUT "File $_ is present & the correct version. $TARGET{$_}\n\n"; $CVALID++; } delete $TARGET{$_}; delete $PROD{$FILE}; } else { print OUT "!File $_ is present but not correct version! Production version is $VER, version present is $TARGET{$_}.\n\n"; $CINVAL++; delete $TARGET{$_}; delete $PROD{$FILE}; } } } # foreach (sort keys (%VIEWS)){ # } } } ($a, $b, $c) = 0; foreach (sort keys (%TARGET)){ @TEMP[$a] = "$_ $TARGET{$_}"; $a++; } foreach (sort keys (%PROD)){ @TEMP2[$b] = "$_ $PROD{$_}"; $b++; } print OUT "\@ prod not present. | Present not at prod.\n"; if ($a > $b){ for ($n=0 , $n = $a, $n++){ printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]); } } else { for ($n=0 , $n = $b, $n++){ printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]); } } print OUT "Production Files Files Present Files Valid Files Invalid\n"; printf OUT " %-5d %-5d %-5d %-5d", ($CPROD, $CTARGET, $CVALID, $CINVAL); close OUT; Output file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !File syoffevs.svl is present but not correct version! Production version is 8.0, version present is 8.1. !File syprb.svl is present but not correct version! Production version is 8.0, version present is 9.0. !File syprs.svl is present but not correct version! Production version is 8.0, version present is 9.0. !File uq124b.svl is present but not correct version! Production version is 1.1, version present is 1.3. !File uq291b.svl is present but not correct version! Production version is 9.0, version present is 7.1. !File uq291s.svl is present but not correct version! Production version is 9.0, version present is 7.1. !File uqafpacb.svl is present but not correct version! Production version is 1.5, version present is 1.3. !File uqafpacs.svl is present but not correct version! Production version is 1.1, version present is 1.0. !File uqpulxb.svl is present but not correct version! Production version is 7.3, version present is 6.3. !File uqpulxs.svl is present but not correct version! Production version is 7.3, version present is 6.3. @ prod not present. | Present not at prod. Production Files Files Present Files Valid Files Invalid 1422 1310 1129 28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ First column is supposed to be the list of files that were in the %PROD hash but didn't find any file on in the %TARGET hash to match it (so it is not on that server). The second column should be a list of files that were present in %TARGET but not in %PROD ( files on the server but not in the repository). Thanks for the help / advice in advance. Any suggestions are welcome. Happy new year! SrA Jensen, USAF -----Original Message----- From: Jensen Kenneth B SrA AFPC/DPDMPQ [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 26, 2002 8:46 AM To: '[EMAIL PROTECTED]' Subject: Formatting output Accidentally sent before I was done writing. I am trying to iterate through two hashes and print each key/value. In one column the key/value from one hash and another column the key/values of the other hash. So the output would look something like this Some header | header for column 2 Key value key value Key value key value Key value key value Key value key value Key value key value Key value key value Key value Key value Etc... Here's what I am doing right now ($a, $b, $c) = 0; foreach (sort keys (%TARGET)){ @TEMP[$a] = "$_ $TARGET{$_}"; $a++; } foreach (sort keys (%PROD)){ @TEMP2[$b] = "$_ $PROD{$_}"; $b++; } print OUT "\@ prod not present. | Present not at prod.\n"; if ($a > $b){ for ($n=0 , $n = $a, $n++){ printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]); } } else { for ($n=0 , $n = $b, $n++){ printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]); } }