Connecting Tech Pros Worldwide Forums | Help | Site Map

comparision of two files

Newbie
 
Join Date: Sep 2006
Posts: 9
#1: Oct 10 '06
Hi Friends,

I am writing a script to compare two files put in two arrays and I expect the those elements which are found in array2 that are not in array1. here there are 2 files Perf.txt which contains some names, and Neu.txt contains some names which are common as well as some different names. Now I am interested only in different names that are not present in Perf.txt

My script:

open (PERF, "Perf.txt");
open (DSA, "Neu.txt");

@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table

# build lookup table
@seen{@Neu} = ();

foreach $item (@Perf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}

foreach(@miss)
{
print "\nElement found ---> $_";
}

When I execute this I am getting all the names which are present in Neu.txt.
Please suggest me what I am wrong.

Thanks and Regards,
Raghavendra S

Newbie
 
Join Date: Sep 2006
Posts: 23
#2: Oct 10 '06

re: comparision of two files


Quote:

Originally Posted by RAGHAVENDRAS

Hi Friends,

I am writing a script to compare two files put in two arrays and I expect the those elements which are found in array2 that are not in array1. here there are 2 files Perf.txt which contains some names, and Neu.txt contains some names which are common as well as some different names. Now I am interested only in different names that are not present in Perf.txt

My script:

open (PERF, "Perf.txt");
open (DSA, "Neu.txt");

@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table

# build lookup table
@seen{@Neu} = ();

foreach $item (@Perf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}

foreach(@miss)
{
print "\nElement found ---> $_";
}

When I execute this I am getting all the names which are present in Neu.txt.
Please suggest me what I am wrong.

Thanks and Regards,
Raghavendra S


hi,

I have just made a little change in your script and it is working at my end fine

I mean it is displaying all the names that are therre in Neu.txt but are not there in perf.txt.

here is the code
open (PERF, "Perf.txt");
open (DSA, "Neu.txt");

@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table

# build lookup table
@seen{@Perf} = ();

foreach $item (@Neuf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}

foreach(@miss)
{
print "\nElement found ---> $_";
}

close(PERF);
close(DEU);


I only made minor changes and run the above script with small set of data and it is working fine at my end
Newbie
 
Join Date: Sep 2006
Posts: 9
#3: Oct 10 '06

re: comparision of two files


Hi Deep022,

Thanks for your suggestion. I forgot to close the files in my script. Now I closed the files but still I am getting all the contents of the file2.

File1: Perf.txt contents are:
CT_SUB_NlsMessageId.dll
PBVCalculationCoordinator.lib
PBVCalculationBE.lib
PBVRefVesselMode.lib
PBVDataCache.lib
PBVMidPlaneMode.lib
PBVResultViewMode.lib
CTNeuroPBVMedDynamicsResource.lib
m_MedCom_CTNeuroPBV3dName.lib
m_MedCom_NeuroPBVSort.lib
PBVLoadHook.lib
NeuroPBVSLHook.lib
PBVResultViewModeCmdObj.lib
PBVCalculationCmdObj.lib
PBVSLHookToLoadHookCmdObj.lib
PBVCalculationProxyReturn.lib
PBVSLHookToLoadHookProxyReturn.lib
PBVResultViewModeProxyReturn.lib
CTAppCommonProxyReturn.lib
CTAppCommonCmdObj.lib
PBVEvents.lib
CTAppCommonDataCache.lib
PBVRefVesselDefinitionCmdObj.lib
PBVCalculationCoordinatorProxyReturn.lib
CTPerfusedBV.lib
CTAppBaseEntities.lib
PBVMidPlaneModeProxyReturn.lib
PBVMidPlaneModeCmdObj.lib
PBVMidPlaneNavigator.lib
PBVROIMode.lib
PBVParallelRangeMode.lib
CT3DSubVPMSetting.lib
PBVWindowingController.lib
PBVDataCacheCmdObj.lib
PBVDataCacheProxyReturn.lib
PBVShowHideMidPlaneLine.lib
PBVIvtUtility.lib
CT3DSubDataCacheCmdObj.lib
PBVMeasurementManipulator.lib
PBVShowHideMidPlaneManipulator.lib
CT3DSubBlendingVACache.lib
CT3DSubRefModeProxyReturn.lib
CT3DSubEvents.lib
CT3DSubRefModeCmdObj.lib
CT3DSubRefMode.lib
CT3DSubRefModeNavigator.lib
CT3DSubRefModeVisualizer.lib
CT3DSubBSCTACalculationCoordinator.lib
CT3DSubBSCTACalculationCoordinatorCommandObjects.l ib
CT3DSubBSCTACalculationCoordinatorProxyReturn.lib
CT3DSubVOIEvents.lib
CT3DSubBSCTACalculationProxyReturn.lib
CT3DSubVOIDataManipulator.lib
CT3DSubGraphicManipulator.lib
CT3DSubVOIDefinitionApplic.lib
CT3DSubVOICmdObj.lib
CT3DSubVOIModeProxyReturn.lib
CTBoneSubCTA.lib
CT3DSubBSCTACalculationBE.lib
CT3DSubBSCTACalculationCmdObj.lib
3DSubMedDynamicsResource.lib
CT3DSubLoadHook.lib
3DSubSLHook.lib

File2: DSA.txt contains:
CT_SUB_NlsMessageId.dll
CT3DSubBlendingVACache.lib
CT3DSubRefModeProxyReturn.lib
CT3DSubEvents.lib
CT3DSubRefModeCmdObj.lib
CT3DSubRefMode.lib
CT3DSubRefModeNavigator.lib
CT3DSubRefModeVisualizer.lib
CT3DSubBSCTACalculationCoordinator.lib
CT3DSubBSCTACalculationCoordinatorCommandObjects.l ib
CT3DSubBSCTACalculationCoordinatorProxyReturn.lib
CT3DSubVOIEvents.lib
CT3DSubBSCTACalculationProxyReturn.lib
CT3DSubVOIDataManipulator.lib
CT3DSubGraphicManipulator.lib
CT3DSubVOIDefinitionApplic.lib
CT3DSubVOICmdObj.lib
CT3DSubVOIModeProxyReturn.lib
CTBoneSubCTA.lib
CT3DSubBSCTACalculationBE.lib
CT3DSubBSCTACalculationCmdObj.lib
3DSubMedDynamicsResource.lib
CT3DSubLoadHook.lib
3DSubSLHook.lib
CT3DSubSLHookToLoadHookProxyReturn.lib
CT3DSubSLHookToLoadHookCmdObj.lib
CT3DSubIVTExchanger.lib
CT3DSubIvtVolumeCreator.lib
CT3DSubStatusLogGuard.lib
CT3DSubIvtImageCreator.lib
CT3DSubSeriesUtility.lib
CT3DSubMergedViewMode.lib
CT3DSubFusedViewMode.lib
CT3DSubVisualAlignmentMode.lib
CT3DSubMergedViewModeProxyReturn.lib
CT3DSubMergedViewModeCmdObj.lib
CT3DSubVoiClipBoxMode.lib
CT3DSubParallelRangeMode.lib
CT3DSubDataCache.lib
CTAppCommonProxyReturn.lib
CTAppCommonCmdObj.lib
CTAppCommonDataCache.lib

Output:

D:\admin>perl missing.pl

Element found ---> CT_SUB_NlsMessageId.dll

Element found ---> PBVCalculationCoordinator.lib

Element found ---> PBVCalculationBE.lib

Element found ---> PBVRefVesselMode.lib

Element found ---> PBVDataCache.lib

Element found ---> PBVMidPlaneMode.lib

Element found ---> PBVResultViewMode.lib

Element found ---> CTNeuroPBVMedDynamicsResource.lib

Element found ---> m_MedCom_CTNeuroPBV3dName.lib

Element found ---> m_MedCom_NeuroPBVSort.lib

Element found ---> PBVLoadHook.lib

Element found ---> NeuroPBVSLHook.lib

Element found ---> PBVResultViewModeCmdObj.lib

Element found ---> PBVCalculationCmdObj.lib

Element found ---> PBVSLHookToLoadHookCmdObj.lib

Element found ---> PBVCalculationProxyReturn.lib

Element found ---> PBVSLHookToLoadHookProxyReturn.lib

Element found ---> PBVResultViewModeProxyReturn.lib

Element found ---> CTAppCommonProxyReturn.lib

Element found ---> CTAppCommonCmdObj.lib

Element found ---> PBVEvents.lib

Element found ---> CTAppCommonDataCache.lib


D:\admin>

What do you say?

With Best Regards,
Raghavendra
Newbie
 
Join Date: Sep 2006
Posts: 23
#4: Oct 10 '06

re: comparision of two files


Quote:

Originally Posted by RAGHAVENDRAS

Hi Deep022,

Thanks for your suggestion. I forgot to close the files in my script. Now I closed the files but still I am getting all the contents of the file2.

File1: Perf.txt contents are:
CT_SUB_NlsMessageId.dll
PBVCalculationCoordinator.lib
PBVCalculationBE.lib
PBVRefVesselMode.lib
PBVDataCache.lib
PBVMidPlaneMode.lib
PBVResultViewMode.lib
CTNeuroPBVMedDynamicsResource.lib
m_MedCom_CTNeuroPBV3dName.lib
m_MedCom_NeuroPBVSort.lib
PBVLoadHook.lib
NeuroPBVSLHook.lib
PBVResultViewModeCmdObj.lib
PBVCalculationCmdObj.lib
PBVSLHookToLoadHookCmdObj.lib
PBVCalculationProxyReturn.lib
PBVSLHookToLoadHookProxyReturn.lib
PBVResultViewModeProxyReturn.lib
CTAppCommonProxyReturn.lib
CTAppCommonCmdObj.lib
PBVEvents.lib
CTAppCommonDataCache.lib
PBVRefVesselDefinitionCmdObj.lib
PBVCalculationCoordinatorProxyReturn.lib
CTPerfusedBV.lib
CTAppBaseEntities.lib
PBVMidPlaneModeProxyReturn.lib
PBVMidPlaneModeCmdObj.lib
PBVMidPlaneNavigator.lib
PBVROIMode.lib
PBVParallelRangeMode.lib
CT3DSubVPMSetting.lib
PBVWindowingController.lib
PBVDataCacheCmdObj.lib
PBVDataCacheProxyReturn.lib
PBVShowHideMidPlaneLine.lib
PBVIvtUtility.lib
CT3DSubDataCacheCmdObj.lib
PBVMeasurementManipulator.lib
PBVShowHideMidPlaneManipulator.lib
CT3DSubBlendingVACache.lib
CT3DSubRefModeProxyReturn.lib
CT3DSubEvents.lib
CT3DSubRefModeCmdObj.lib
CT3DSubRefMode.lib
CT3DSubRefModeNavigator.lib
CT3DSubRefModeVisualizer.lib
CT3DSubBSCTACalculationCoordinator.lib
CT3DSubBSCTACalculationCoordinatorCommandObjects.l ib
CT3DSubBSCTACalculationCoordinatorProxyReturn.lib
CT3DSubVOIEvents.lib
CT3DSubBSCTACalculationProxyReturn.lib
CT3DSubVOIDataManipulator.lib
CT3DSubGraphicManipulator.lib
CT3DSubVOIDefinitionApplic.lib
CT3DSubVOICmdObj.lib
CT3DSubVOIModeProxyReturn.lib
CTBoneSubCTA.lib
CT3DSubBSCTACalculationBE.lib
CT3DSubBSCTACalculationCmdObj.lib
3DSubMedDynamicsResource.lib
CT3DSubLoadHook.lib
3DSubSLHook.lib

File2: DSA.txt contains:
CT_SUB_NlsMessageId.dll
CT3DSubBlendingVACache.lib
CT3DSubRefModeProxyReturn.lib
CT3DSubEvents.lib
CT3DSubRefModeCmdObj.lib
CT3DSubRefMode.lib
CT3DSubRefModeNavigator.lib
CT3DSubRefModeVisualizer.lib
CT3DSubBSCTACalculationCoordinator.lib
CT3DSubBSCTACalculationCoordinatorCommandObjects.l ib
CT3DSubBSCTACalculationCoordinatorProxyReturn.lib
CT3DSubVOIEvents.lib
CT3DSubBSCTACalculationProxyReturn.lib
CT3DSubVOIDataManipulator.lib
CT3DSubGraphicManipulator.lib
CT3DSubVOIDefinitionApplic.lib
CT3DSubVOICmdObj.lib
CT3DSubVOIModeProxyReturn.lib
CTBoneSubCTA.lib
CT3DSubBSCTACalculationBE.lib
CT3DSubBSCTACalculationCmdObj.lib
3DSubMedDynamicsResource.lib
CT3DSubLoadHook.lib
3DSubSLHook.lib
CT3DSubSLHookToLoadHookProxyReturn.lib
CT3DSubSLHookToLoadHookCmdObj.lib
CT3DSubIVTExchanger.lib
CT3DSubIvtVolumeCreator.lib
CT3DSubStatusLogGuard.lib
CT3DSubIvtImageCreator.lib
CT3DSubSeriesUtility.lib
CT3DSubMergedViewMode.lib
CT3DSubFusedViewMode.lib
CT3DSubVisualAlignmentMode.lib
CT3DSubMergedViewModeProxyReturn.lib
CT3DSubMergedViewModeCmdObj.lib
CT3DSubVoiClipBoxMode.lib
CT3DSubParallelRangeMode.lib
CT3DSubDataCache.lib
CTAppCommonProxyReturn.lib
CTAppCommonCmdObj.lib
CTAppCommonDataCache.lib

Output:

D:\admin>perl missing.pl

Element found ---> CT_SUB_NlsMessageId.dll

Element found ---> PBVCalculationCoordinator.lib

Element found ---> PBVCalculationBE.lib

Element found ---> PBVRefVesselMode.lib

Element found ---> PBVDataCache.lib

Element found ---> PBVMidPlaneMode.lib

Element found ---> PBVResultViewMode.lib

Element found ---> CTNeuroPBVMedDynamicsResource.lib

Element found ---> m_MedCom_CTNeuroPBV3dName.lib

Element found ---> m_MedCom_NeuroPBVSort.lib

Element found ---> PBVLoadHook.lib

Element found ---> NeuroPBVSLHook.lib

Element found ---> PBVResultViewModeCmdObj.lib

Element found ---> PBVCalculationCmdObj.lib

Element found ---> PBVSLHookToLoadHookCmdObj.lib

Element found ---> PBVCalculationProxyReturn.lib

Element found ---> PBVSLHookToLoadHookProxyReturn.lib

Element found ---> PBVResultViewModeProxyReturn.lib

Element found ---> CTAppCommonProxyReturn.lib

Element found ---> CTAppCommonCmdObj.lib

Element found ---> PBVEvents.lib

Element found ---> CTAppCommonDataCache.lib


D:\admin>

What do you say?

With Best Regards,
Raghavendra

====
Hi Raghavendra,

apart from the file closing I have made few other changes in the code(see the comments)
.
open (PERF, "Perf.txt");
open (DSA, "Neu.txt");

@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table

# build lookup table
@seen{@Perf} = (); # changed to @Perf instead of @Neu

foreach $item (@Neu) # changes to @Neu instead of @Perf
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}

foreach(@miss)
{
print "\nElement found ---> $_";
}

#added ther following two lines
close(PERF);
close(DEU);

When I execute this above code the following output comes:
Element found ---> CT3DSubSLHookToLoadHookProxyReturn.lib



Element found ---> CT3DSubSLHookToLoadHookCmdObj.lib



Element found ---> CT3DSubIVTExchanger.lib



Element found ---> CT3DSubIvtVolumeCreator.lib



Element found ---> CT3DSubStatusLogGuard.lib



Element found ---> CT3DSubIvtImageCreator.lib



Element found ---> CT3DSubSeriesUtility.lib



Element found ---> CT3DSubMergedViewMode.lib



Element found ---> CT3DSubFusedViewMode.lib



Element found ---> CT3DSubVisualAlignmentMode.lib



Element found ---> CT3DSubMergedViewModeProxyReturn.lib



Element found ---> CT3DSubMergedViewModeCmdObj.lib



Element found ---> CT3DSubVoiClipBoxMode.lib



Element found ---> CT3DSubParallelRangeMode.lib



Element found ---> CT3DSubDataCache.lib

which is different from the one you generated.

can you please paste this code and run it on the data files and let me know the result...



with regards,
dipak
Newbie
 
Join Date: Sep 2006
Posts: 9
#5: Oct 11 '06

re: comparision of two files


Hi Deepak,

Thanks for your suggestion. It works.

Thanks&BestRegards,
Raghavendra
Newbie
 
Join Date: Jan 2007
Posts: 1
#6: Jan 29 '07

re: comparision of two files


Quote:

Originally Posted by deep022in

====
Hi Raghavendra,

apart from the file closing I have made few other changes in the code(see the comments)
.
open (PERF, "Perf.txt");
open (DSA, "Neu.txt");

@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table

# build lookup table
@seen{@Perf} = (); # changed to @Perf instead of @Neu

foreach $item (@Neu) # changes to @Neu instead of @Perf
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}

foreach(@miss)
{
print "\nElement found ---> $_";
}

#added ther following two lines
close(PERF);
close(DEU);

When I execute this above code the following output comes:
Element found ---> CT3DSubSLHookToLoadHookProxyReturn.lib



Element found ---> CT3DSubSLHookToLoadHookCmdObj.lib



Element found ---> CT3DSubIVTExchanger.lib



Element found ---> CT3DSubIvtVolumeCreator.lib



Element found ---> CT3DSubStatusLogGuard.lib



Element found ---> CT3DSubIvtImageCreator.lib



Element found ---> CT3DSubSeriesUtility.lib



Element found ---> CT3DSubMergedViewMode.lib



Element found ---> CT3DSubFusedViewMode.lib



Element found ---> CT3DSubVisualAlignmentMode.lib



Element found ---> CT3DSubMergedViewModeProxyReturn.lib



Element found ---> CT3DSubMergedViewModeCmdObj.lib



Element found ---> CT3DSubVoiClipBoxMode.lib



Element found ---> CT3DSubParallelRangeMode.lib



Element found ---> CT3DSubDataCache.lib

which is different from the one you generated.

can you please paste this code and run it on the data files and let me know the result...



with regards,
dipak


Hi,
is there a way where I can print out the elements which exists in both files? I hope you could help me. Thanks!
Reply