Ok monks, I have a little bit of a dilemma here. I was asked to write a short script to list the differences of files inside each directory.
To provide some background, we have a production environment and a development environment for our payroll application, and we want to see what source files are different between the two. There are four directories in the development environment, and each one has a corresponding directory in the production environment.
To make a long story short, my hacked together script became very popular and they now need me to add to it. My problem is that of trying to maintain the thing, as it is now huge, and in dire need of some help, so that I can easily modify it. All I need is pointers in the right direction. Thanks.
#!/opt/perl5/bin/perl -w use strict; use File::Slurp; # The production files will be listed in # the source hashes my (%iqs,%iqs_source,%prg,%prg_source); my (%spg,%spg_source,%tpr,%tpr_source); my $report="/home/mis/tstanley/SourceDiff.rpt"; ## Read each directory and get the file names my @iqs_src=read_dir('/dsmpayroll/iqs-source'); my @iqs=read_dir('/dsmmigrate/development/iqs'); my @prg_src=read_dir('/dsmpayroll/prg-source'); my @prg=read_dir('/dsmmigrate/development/prg'); my @spg_src=read_dir('/dsmpayroll/spg-source'); my @spg=read_dir('/dsmmigrate/development/spg'); my @tpr_src=read_dir('/dsmpayroll/tpr-source'); my @tpr=read_dir('/dsmmigrate/development/tpr'); ## Change into each directory and go through the files ## and get the sum of each file and put into a hash chdir('/dsmpayroll/iqs-source'); foreach(@iqs_src){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $iqs_source{$_}=$x; } chdir('/dsmpayroll/prg-source'); foreach(@prg_src){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $prg_source{$_}=$x; } chdir('/dsmpayroll/spg-source'); foreach(@spg_src){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $spg_source{$_}=$x; } chdir('/dsmpayroll/tpr-source'); foreach(@tpr_src){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $tpr_source{$_}=$x; } chdir('/dsmmigrate/development/iqs'); foreach(@iqs){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $iqs{$_}=$x; } chdir('/dsmmigrate/development/prg'); foreach(@prg){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $prg{$_}=$x; } chdir('/dsmmigrate/development/spg'); foreach(@spg){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $spg{$_}=$x; } chdir('/dsmmigrate/development/tpr'); foreach(@tpr){ my $sum=`sum $_`; my ($x,$y,$z)=split /\s+/,$sum; $tpr{$_}=$x; } ## Open the report file open RPT,">$report"||die "Unable to open $report: $!\n"; my $date=`date`; print RPT "$date\n\n"; ## For each set of directories, we find the common file names in them, + and ## then go through those files and compare the sums. If the Production + file ## is different, we write it out to the report file. print RPT "IQS Source Files\n"; print RPT "================\n"; my @iqs_common; foreach(keys %iqs){ next if $_=~/cob/; ## This is an empty directory that exists in each + source directory push(@iqs_common,$_) if exists $iqs_source{$_}; } foreach(@iqs_common){ next if $_=/\.ffl|\.lst/; ## If a file has these extensions, they ca +n be ignored my $prod=$iqs_source{$_}; my $dev=$iqs{$_}; next if !defined $prod and !defined $dev; ## Error handling if all f +iles match or can be ignored if ($prod != $dev){ print RPT "/dsmpayroll/iqs-source/$_\n"; } } print RPT "\n\nPRG Source Files\n"; print RPT "================\n"; my @prg_common; foreach(keys %prg){ next if $_=~/cob/; ## This is an empty directory that exists in each + source directory push(@prg_common,$_) if exists $prg_source{$_}; } foreach(@prg_common){ next if $_=~/\.ffl|\.lst/; ## If a file has these extensions, they c +an be ignored my $prod=$prg_source{$_}; my $dev=$prg{$_}; next if !defined $prod and !defined $dev; ## Error handling if all f +iles match or can be ignored if($prod != $dev){ print RPT "/dsmpayroll/prg-source/$_\n"; } } print RPT "\n\nSPG Source Files\n"; print RPT "================\n"; my @spg_common; foreach(keys %spg){ next if $_=~/cob/; ## This is an empty directory that exists in each + source directory push(@spg_common,$_) if exists $spg_source{$_}; } foreach(@spg_common){ next if $_=~/\.ffl|\.lst/; ## If a file has these extensions, they c +an be ignored my $prod=$spg_source{$_}; my $dev=$spg{$_}; next if !defined $prod and !defined $dev; ## Error handling if all f +iles match or can be ignored if($prod != $dev){ print RPT "/dsmpayroll/spg-source/$_\n"; } } print RPT "\n\nTPR Source Files\n"; print RPT "================\n"; my @tpr_common; foreach(keys %tpr){ next if $_=~/cob/; ## This is an empty directory that exists in each + source directory push(@tpr_common,$_) if exists $tpr_source{$_}; } foreach(@tpr_common){ next if $_=~/\.ffl|\.lst/; ## If a file has these extensions, they c +an be ignored my $prod=$tpr_source{$_}; my $dev=$tpr{$_}; next if !defined $prod and !defined $dev; ## Error handling if all f +iles match or can be ignored if($prod != $dev){ print RPT "/dsmpayroll/tpr-source/$_\n"; } } close RPT;

TStanley
--------
The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke

In reply to File Differences by TStanley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.