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 | Creating Excel Files
- Perl | Reading Excel Files
- Perl | Finding Files and Directories
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- Perl vs C/C++
- Perl | GET vs POST in CGI
- Perl | qw Operator
- Perl vs Java
- Use of print() and say() in Perl
- Perl | given-when Statement
- Perl | last in loop
- Perl | cos() Function
- Perl | Modules
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.