Important alert: (current site time 7/15/2013 9:36:05 PM EDT)
 

VB icon

readAndCompare.pl

Email
Submitted on: 9/5/2000 4:04:29 PM
By: James Aguirre 
Level: Advanced
User Rating: By 6 Users
Compatibility: 5.0 (all versions)
Views: 14564
 
     This script was created with the intent of comparing two files, one in a production environment with that under source code control.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: readAndCompare.pl
= Description:This script was created with
the intent of comparing two files, one in a production
environment with that under source code control.
= By: James Aguirre
=
= Inputs:Inputs:
Paths to files you'd like 
to difference.
=
= Returns:Message if the compared files are different.
=
= Assumes:Using perl -w yields an irrelivant 
message for line 21
The comparison wil be *-Binary-* 
so whitespace
is NOT ignored.
=
= Side Effects:Files are opened 
as ReadOnly.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=127&lngWId=6=for details.=**************************************

#################################################
# File: readAndCompare.pl 
# 
# Synopsis: This file was written as a replacement 
# for the DOS file compare command, and is 
# equivalent to fc /b (BINARY) <FILE> <FILE>
# so whitespace is NOT IGNORED. It was created with
# the intent of compareing files in a production
# environment with that under source code control
#
# Written by: James Aguirre -- 08-29-2000 
#################################################
!#usr/bin/perl
# provide the paths to the file 
 # Grab the paths from cmd line. 
print "Enter Path to Production file.\n";
chomp($pPath=<STDIN>);
##### DEBUG #####
#print "Path Given was $pPath\n";
print "Enter Path to Versioned file.\n";
chomp($vPath=<STDIN>);
# Check that the command line args were not equal.
if($pPath eq $vPath)
{
print "Cannot compare the same file\n";
exit;
}
##### DEBUG #####
#print "Path Given was $vPath\n";
# Open the production file.
open(PROD, "< $pPath") or die "Can't read the production file";
	
# write to a scalar
while(<PROD>)
{
	 $pHandle .=$_
}
# Close the filehandle
close(PROD) or die "Can't close the production file.";	 
	 
# Open the versioned file Read Only.
open(VERS, "< $vPath") or die "Can't read the versioned file";
 # write to a scalar
while(<VERS>)
{
	 $vHandle .=$_
}
# Close the filehandle
close(VERS) or die "Can't close the versioned file.";
# Compare the scalars 
###### NOTE: this is a -- BINARY -- compare. 
if($vHandle ne $pHandle)
	{
 print "Production file differs from versioned file.\n";
	}
else
{
# Clever alert Message -? 
exit;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/5/2000 6:45:21 PMGerry

go jim!
(If this comment was disrespectful, please report it.)

 
10/23/2000 5:39:31 PMjonnysoft

Not really very complicated, is it?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.