![]() |
VOOZH | about |
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.
Syntax:
use File::Compare;
$compare = compare('FILE_NAME_1', 'FILE_NAME_2');
Note:
- Same Content: Return Value [0]
- Different Content: Return Value [1]
- Error in Accessing Files: Return Value [-1]
Example:
Files Present in the Folder. π Image
When the content of the Files is same:
Output:
When the content of the Files is different:
Output:
When the file is not accessible:
Output: