Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to compare the matching between field 5 for each line for both files contents of Testbase.txtmy($snapshot, $baseline); # Defining txt files # First file $snapshot = "./302-snap.txt"; # List of Svcs currently running loc at c:\perl # Second file $baseline = "./302-base.txt"; # List of All Svcs which should be running my(@arr1, @arr2, @result); # Defining arrays my($fld1, $fld2, $fld3, $fld4); # Defining variables for fields my($match, $cnt, $val1, $val2, $finalresult); # Defining scalar variables $match = "N"; #Open snapshot file and insert every line into @arr1 open(SNAPSHOT, $snapshot) or die "Unable to open $snapshot."; # Open t +he txt file and place it in filehandle $cnt = 0; while ( <SNAPSHOT> ) # Looping thru the filehandle snapshot { $arr1[$cnt] = $_; $cnt = $cnt + 1; } close (SNAPSHOT); # close the filehandle snapshot #Open baseline file and insert every line into @arr2 open(BASELINE, $baseline) or die "Unable to open $baseline."; # Open t +he txt file and place it in filehandle $cnt = 0; while ( <BASELINE> ) # Looping thru the filehandle baseline { $arr2[$cnt] = $_; $cnt = $cnt + 1; } close (BASELINE); # close filehandle baseline # Outer loop is for baseline file # Inner loop is for snapshot file # Taking one element from @arr2 (baseline) and comparing it with all t +he elements in @arr1(snapshot) and # If their is no match then insert that name into @result. $cnt = 0; foreach $val2 (@arr2) # referring to baseline { foreach $val1 (@arr1) # referring to snapshot { if ($val1 eq $val2) { $match = "Y"; } } if ($match eq "N") { $result[$cnt] = $val2; $cnt = $cnt + 1; } $match = "N"; } $finalresult = 0; # initializing to zero foreach $val1 (@result) { $finalresult = $finalresult + 1; } if ($finalresult > 0 ) { print "\nList of SICK Siebel-Components \n\n"; # If some svc is not functioning foreach $val1 (@result) { ($fld1,$fld2,$fld3,$fld4) = split(/\|/,"$val1");# separating req fields for output print "Svc-Component $fld4, of Siebel-Svc '$fld3'($fld2)\n"; } } else { print "\nAll Siebel-Components are Functioning Fine\n"; # When all sv +cs are running fine }
contents of snapbase.txtS2_NXLKPRD|SMECacheMgr|Analysis Cache Manager|SMECacheMgr|Enabled|Runn +ing|08/24/2001 11:00:49|20|0|1| S2_NXLKPRD|SMEProxyMgr|Analysis Proxy Manager|SMEProxyMgr|Enabled|Runn +ing|08/24/2001 11:00:49|20|0|1|
S2_NXLKPRD|SMECacheMgr|Analysis Cache Manager|SMECacheMgr|error|Runnin +g|08/24/2001 11:00:49|20|0|1| S2_NXLKPRD|SMEProxyMgr|Analysis Proxy Manager|SMEProxyMgr|Enabled|Runn +ing|08/24/2001 11:00:49|20|0|1|
Edit Masem 2001-08-28 - Code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparison
by chromatic (Archbishop) on Aug 29, 2001 at 00:59 UTC |