In Perl, we can easily compare the content of two files by using the
File::Compare module. This module provides a function called
compare, which helps in comparing the content of two files specified to it as arguments. If the data present in both the files comes out to be same, the function returns 0 as the output, if the data in the passed files is different, the return value is 1 and if there is any error occurred while accessing the specified/passed files, it returns the value as -1.
use File::Compare; $compare = compare('FILE_NAME_1', 'FILE_NAME_2');
Same Content: Return Value  Different Content: Return Value  Error in Accessing Files: Return Value [-1]
Files Present in the Folder.
When the content of the Files is same:
When the content of the Files is different:
When the file is not accessible:
- Perl | Comparing Scalars
- Perl | Finding Files and Directories
- Perl | Reading Excel Files
- Perl | Creating Excel Files
- Perl | Basic Syntax of a Perl Program
- Perl vs C/C++
- Perl | References
- Perl | CGI Programming
- Packages in Perl
- Perl | tell() Function
- Perl | my keyword
- Perl | Variables
- Perl | y Operator
- Perl | tr Operator
- Perl | GET vs POST in CGI
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.