use strict; my (%old, %new); my ($dir, $fname, $size, $dirprinted, $sectionprinted); if((scalar @ARGV) != 2) { die "Usage: perl dirdiff \n"; } open(FILE, $ARGV[0]) or die "Failure to open $ARGV[0]: $!"; while() { chomp; if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) { $old{$dir}{$fname} = $size; } } close(FILE); open(FILE, $ARGV[1]) or die "Failure to open $ARGV[1]: $!"; while() { chomp; if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) { $new{$dir}{$fname} = $size; } } close(FILE); print("Files:\n"); # # added entries # $sectionprinted = 0; foreach $dir (sort keys %new) { $dirprinted = 0; foreach $fname (sort keys %{$new{$dir}}) { if(!defined($old{$dir}{$fname})) { if(!$sectionprinted) { $sectionprinted = 1; print(" Added:\n"); } if(!$dirprinted) { print(" $dir\n"); $dirprinted = 1; } print(" $fname\n"); } } } # # deleted entries # $sectionprinted = 0; foreach $dir (sort keys %old) { $dirprinted = 0; foreach $fname (sort keys %{$old{$dir}}) { if(!defined($new{$dir}{$fname})) { if(!$sectionprinted) { $sectionprinted = 1; print(" Deleted:\n"); } if(!$dirprinted) { print(" $dir\n"); $dirprinted = 1; } print(" $fname\n"); } } } # # changed entries # $sectionprinted = 0; foreach $dir (sort keys %old) { $dirprinted = 0; foreach $fname (sort keys %{$old{$dir}}) { if(defined($new{$dir}{$fname})) { if($new{$dir}{$fname} == $old{$dir}{$fname}) { next; } if(!$sectionprinted) { $sectionprinted = 1; print(" Changed:\n"); } if(!$dirprinted) { print(" $dir\n"); $dirprinted = 1; } print(" $fname\n"); } } }