Find difference between two text files in Perl

#!/usr/bin/env perl
use strict;
use warnings;
use Text::Diff;

my $file1 = $ARGV[0];
my $file2 = $ARGV[1];

my $diffs = diff $file1,$file2;
my @strings = split("\n",$diffs);

foreach(@strings)
{
    print $_."\n";
}

This Perl script compares two text files and prints their differences using the Text::Diff module. You pass the two file paths as arguments and it reports the changed lines, much like the Unix diff command.

Doing this in code is useful inside larger pipelines, for example checking generated output against an expected baseline or flagging configuration drift between environments.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram