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

Salutations fellow monks,

Problem: I need to compare the output of a certain ClearCase MultiSite command from two different sites.

Sample data from local site:

For VOB replica "\AXIS": Actual oplog IDs for row "foax_axis_AXIS_3" (@ fors19aa): oid:a660e345.b4dc4bbf.afd1.4f:2e:af:d0:33:74=555770 (foax_axis_ +AXIS_3) oid:7d7aedf3.575b4c9a.aa8d.cb:be:05:68:e1:ab=6694451 (sisl_AXIS) + oid:3acebdef.56e143af.84d3.8f:5e:b3:a4:4a:31=25744475 (smsax_AXIS +) oid:3f1b3b0b.519042b4.93a9.ae:64:52:ad:11:26=5 (smsax_axis +_3) For VOB replica "\PROJECTS": Actual oplog IDs for row "fo_mas_PROJECTS" (@ fors19aa): oid:d4e9cd09.dcad4cce.8559.72:19:f4:ee:f8:11=1804833 (fo_mas_PRO +JECTS) oid:ed0b2a97.1d5a4cd4.8b48.86:07:fb:09:68:52=14998 (heitec_mas +_PROJECTS_3) oid:eefd6347.471443ea.814a.d0:da:e8:d4:fd:c7=25557 (keco_PROJE +CTS_2) oid:039b84e2.4f8d4449.9676.ce:37:80:55:4e:ac=7527 (sisl_PROJE +CTS_2) oid:660856b5.68604e0c.81a8.94:6e:f9:ac:54:ef=832 (vplus_mas_ +PROJECTS_2) For VOB replica "\Newcor": Actual oplog IDs for row "newcor_forchheim" (@ fors19ya.ww005.siemens. +net): oid:73e6ca76.f3eb41c9.a34a.ba:13:ba:f2:d7:e1=386 (newcor_for +chheim) oid:6d1fa895.96d94d5a.8f58.d5:7a:a3:06:a4:5f=28524 (newcor_hof +fman_estate) oid:a8d006a2.2f5644bc.bfe4.83:e2:ad:fc:d8:fc=3099634 (newcor_ind +ia)

Sample data from remote site:

For VOB replica "\AXIS": Actual oplog IDs for row "smsax_AXIS" (@ hesba08a): oid:a660e345.b4dc4bbf.afd1.4f:2e:af:d0:33:74=555775 (foax_axis_ +AXIS_3) oid:7d7aedf3.575b4c9a.aa8d.cb:be:05:68:e1:ab=6694474 (sisl_AXIS) + oid:3acebdef.56e143af.84d3.8f:5e:b3:a4:4a:31=25773996 (smsax_AXIS +) oid:3f1b3b0b.519042b4.93a9.ae:64:52:ad:11:26=5 (smsax_axis +_3) For VOB replica "\PROJECTS": Actual oplog IDs for row "smsax_projects_2" (@ hesba08a): oid:d4e9cd09.dcad4cce.8559.72:19:f4:ee:f8:11=1805193 (fo_mas_PRO +JECTS) oid:ed0b2a97.1d5a4cd4.8b48.86:07:fb:09:68:52=15004 (heitec_mas +_PROJECTS_3) oid:eefd6347.471443ea.814a.d0:da:e8:d4:fd:c7=25569 (keco_PROJE +CTS_2) oid:039b84e2.4f8d4449.9676.ce:37:80:55:4e:ac=7553 (sisl_PROJE +CTS_2) oid:660856b5.68604e0c.81a8.94:6e:f9:ac:54:ef=833 (vplus_mas_ +PROJECTS_2) For VOB replica "\Newcor": Actual oplog IDs for row "newcor_hoffman_estate" (@ hesba07a.ww005.sie +mens.net): oid:73e6ca76.f3eb41c9.a34a.ba:13:ba:f2:d7:e1=388 (newcor_for +chheim) oid:6d1fa895.96d94d5a.8f58.d5:7a:a3:06:a4:5f=28541 (newcor_hof +fman_estate) oid:a8d006a2.2f5644bc.bfe4.83:e2:ad:fc:d8:fc=3099770 (newcor_ind +ia)

What I want to do:

These outputs are in a file. I will try my best to explain it with an example.

For the "\AXIS", I need to compare one value in the table between the two outputs.

So first I find out the table belonging to "\AXIS" in both files. Then I select the table belonging to "foax_axis_AXIS_3" from local site and the table belonging to "smsax_AXIS" form the remote site.

Here I look for the line containing "smsax_AXIS" and find that the values are 25773996 and 25744475.

This tells me that my local site has all the info and more form the remote site. If the values ahd ben the reverses, I would know that I was missing information.

Any ideas how I could achieve this comparison??

If the explanation is not clear, I am ready to call and try to explain the situation..

Code I tried:

for(my $i = 0; $i < scalar(@epochList); $i++) { my $line = $epochList[$i]; chomp($line); next if((!$line) || ($line =~ /^;/) || ($line =~ /deleted/)); print $line . "\n" if($debugLevel >= 5); ### if line contains the VOB Tag, read in the following info until + next VOB Tag is reached ### VOB Tag is hash key in this case if($line =~ /^\s*For VOB replica \"(.*)\"\s*/i) { #### create a hash for VOB info, with VOB Tag as key $tmpVOBTag = $1; $vobInfoHashRef = $epochFileHash{$1} ||= {}; print "level 1" . "$_\n"; print "epoch file hash ---" . $epochFileHash{$tmpVOBTag} . "\n +"; next; } # Get the replica name. if($line =~ /^\s*Actual oplog IDs for row \"(.*)\"\s*/i) { # Store the key to the hash as replica_name $tmpReplicaName = $1; my $replicaInfoHashRef = ${$epochFileHash{$tmpVOBTag}}{$1} ||= + {}; print "level 2" . "$_\n"; print "epoch file hash ---" . ${$epochFileHash{$tmpVOBTag}}{$t +mpReplicaName} . "\n"; next; } # Get oplogs rows ##### similar info found previously, but only once ##### create an array #### ${$epochFileHash{$tmpVOBTag}}{$tmpReplicaName} if(ref(${$epochFileHash{$tmpVOBTag}}{$tmpReplicaName}) ne "ARRAY") { my $tmpReplicaInfoVal = ""; print"value is not an array" . "\n" if($debugLevel >= 5); $tmpReplicaInfoVal = ${$epochFileHash{$tmpVOBTag}}{$tmpReplica +Name}; $vobInfoHashRef->{$replicaInfoHashRef} = (()); push(@{$vobInfoHashRef->{$replicaInfoHashRef}}, $tmpReplicaInf +oVal); } ##### already inserted as array, just push new info into array print "value is an array" . "\n" if($debugLevel >= 5); push(@{$vobInfoHashRef->{$replicaInfoHashRef}}, $line); } ##-------------------------------------------------------------------- +------ ### dump out the whole hash onto the screen, debugging purposes only if($debugLevel >= 0) { print "-" x 50 . "\n"; foreach my $key(keys %epochFileHash) { print "$key-->"; if(ref($epochFileHash{$key}) ne "HASH") { print "$epochFileHash{$key}" . "\n"; } else { # print keys %{ $epochFileHash{$key} }; foreach my $compInfo(keys %{ $epochFileHash{$key} }) { print "$compInfo==>"; if(ref($epochFileHash{$key}->{$compInfo}) ne "ARRAY") { print "$compInfo-->$epochFileHash{$key}->{$compInf +o}" . "\n"; } else { print scalar(@{$epochFileHash{$key}->{$compInfo}}) +; foreach my $compInfoVal(@{$epochFileHash{$key}->{$ +compInfo}}) { print "$compInfoVal" . "\n"; } } } } print "-" x 30 . "\n"; } }

Thanks and regards

Sriram

Replies are listed 'Best First'.
Re: nested hash to parse and compare MultiSite data
by GrandFather (Saint) on Nov 05, 2008 at 09:31 UTC

    If I understand what you want then the following should help:

    use strict; use warnings; my $local = <<'DATA'; For VOB replica "\AXIS": Actual oplog IDs for row "foax_axis_AXIS_3" (@ fors19aa): oid:a660e345.b4dc4bbf.afd1.4f:2e:af:d0:33:74=555770 (foax_axis_ +AXIS_3) oid:7d7aedf3.575b4c9a.aa8d.cb:be:05:68:e1:ab=6694451 (sisl_AXIS) oid:3acebdef.56e143af.84d3.8f:5e:b3:a4:4a:31=25744475 (smsax_AXIS +) oid:3f1b3b0b.519042b4.93a9.ae:64:52:ad:11:26=5 (smsax_axis +_3) For VOB replica "\PROJECTS": Actual oplog IDs for row "fo_mas_PROJECTS" (@ fors19aa): oid:d4e9cd09.dcad4cce.8559.72:19:f4:ee:f8:11=1804833 (fo_mas_PRO +JECTS) oid:ed0b2a97.1d5a4cd4.8b48.86:07:fb:09:68:52=14998 (heitec_mas +_PROJECTS_3) oid:eefd6347.471443ea.814a.d0:da:e8:d4:fd:c7=25557 (keco_PROJE +CTS_2) oid:039b84e2.4f8d4449.9676.ce:37:80:55:4e:ac=7527 (sisl_PROJE +CTS_2) oid:660856b5.68604e0c.81a8.94:6e:f9:ac:54:ef=832 (vplus_mas_ +PROJECTS_2) For VOB replica "\Newcor": Actual oplog IDs for row "newcor_forchheim" (@ fors19ya.ww005.siemens. +net): oid:73e6ca76.f3eb41c9.a34a.ba:13:ba:f2:d7:e1=386 (newcor_for +chheim) oid:6d1fa895.96d94d5a.8f58.d5:7a:a3:06:a4:5f=28524 (newcor_hof +fman_estate) oid:a8d006a2.2f5644bc.bfe4.83:e2:ad:fc:d8:fc=3099634 (newcor_ind +ia) DATA my $remote = <<'DATA'; For VOB replica "\AXIS": Actual oplog IDs for row "smsax_AXIS" (@ hesba08a): oid:a660e345.b4dc4bbf.afd1.4f:2e:af:d0:33:74=555775 (foax_axis_ +AXIS_3) oid:7d7aedf3.575b4c9a.aa8d.cb:be:05:68:e1:ab=6694474 (sisl_AXIS) oid:3acebdef.56e143af.84d3.8f:5e:b3:a4:4a:31=25773996 (smsax_AXIS +) oid:3f1b3b0b.519042b4.93a9.ae:64:52:ad:11:26=5 (smsax_axis +_3) For VOB replica "\PROJECTS": Actual oplog IDs for row "smsax_projects_2" (@ hesba08a): oid:d4e9cd09.dcad4cce.8559.72:19:f4:ee:f8:11=1805193 (fo_mas_PRO +JECTS) oid:ed0b2a97.1d5a4cd4.8b48.86:07:fb:09:68:52=15004 (heitec_mas +_PROJECTS_3) oid:eefd6347.471443ea.814a.d0:da:e8:d4:fd:c7=25569 (keco_PROJE +CTS_2) oid:039b84e2.4f8d4449.9676.ce:37:80:55:4e:ac=7553 (sisl_PROJE +CTS_2) oid:660856b5.68604e0c.81a8.94:6e:f9:ac:54:ef=833 (vplus_mas_ +PROJECTS_2) For VOB replica "\Newcor": Actual oplog IDs for row "newcor_hoffman_estate" (@ hesba07a.ww005.sie +mens.net): oid:73e6ca76.f3eb41c9.a34a.ba:13:ba:f2:d7:e1=388 (newcor_for +chheim) oid:6d1fa895.96d94d5a.8f58.d5:7a:a3:06:a4:5f=28541 (newcor_hof +fman_estate) oid:a8d006a2.2f5644bc.bfe4.83:e2:ad:fc:d8:fc=3099770 (newcor_ind +ia) DATA open my $inFile, '<', \$local; my %localData = load ($inFile); close $inFile; open $inFile, '<', \$remote; my %remoteData = load ($inFile); close $inFile; for my $dir (sort keys %remoteData) { if (! exists $localData{$dir}) { print "Directory $dir exists remotely but not locally\n"; next; } for my $file (sort keys %{$remoteData{$dir}}) { if (! exists $localData{$dir}{$file}) { print "File $file exists in remote directory $dir but not +locally\n"; next; } my $remoteVers = $remoteData{$dir}{$file}{vers}; my $localVers = $localData{$dir}{$file}{vers}; if ($localVers < $remoteVers) { print "Remote file $dir/$file at version $remoteVers is ne +wer than the local file at version $localVers\n"; } } } sub load { my ($inFile) = @_; my %data; local $/ = 'For VOB replica '; while (<$inFile>) { chomp; next unless m!"\\([^"]+)"!; my $dir = $1; my @lines = /(oid\S+\s+\(\S+\))/g; for (@lines) { next unless /oid:([^=]+)=(\d+)\s+\(([^)]+)/; $data{$dir}{$3} = {id => $1, vers => $2}; } } return %data; }

    Prints:

    Remote file AXIS/foax_axis_AXIS_3 at version 555775 is newer than the +local file at version 555770 Remote file AXIS/sisl_AXIS at version 6694474 is newer than the local +file at version 6694451 Remote file AXIS/smsax_AXIS at version 25773996 is newer than the loca +l file at version 25744475 Remote file Newcor/newcor_forchheim at version 388 is newer than the l +ocal file at version 386 Remote file Newcor/newcor_hoffman_estate at version 28541 is newer tha +n the local file at version 28524 Remote file Newcor/newcor_india at version 3099770 is newer than the l +ocal file at version 3099634 Remote file PROJECTS/fo_mas_PROJECTS at version 1805193 is newer than +the local file at version 1804833 Remote file PROJECTS/heitec_mas_PROJECTS_3 at version 15004 is newer t +han the local file at version 14998 Remote file PROJECTS/keco_PROJECTS_2 at version 25569 is newer than th +e local file at version 25557 Remote file PROJECTS/sisl_PROJECTS_2 at version 7553 is newer than the + local file at version 7527 Remote file PROJECTS/vplus_mas_PROJECTS_2 at version 833 is newer than + the local file at version 832

    I don't guarantee my nomenclature matches anything real however. ;)


    Perl reduces RSI - it saves typing
      Thanks a lot GrandFather. I think your solution would work.
Re: nested hash to parse and compare MultiSite data
by moritz (Cardinal) on Nov 05, 2008 at 08:35 UTC
    Did you look at CPAN? There seem to be a few modules already that work with clearcase, maybe one of them can help you.

    Also, what have you tried so far? (Update: OP supplied code now, so you can ignore this line...)