################################################# #!/usr/bin/perl #InventoryReport.pl ###Good Perl practice: use warnings; use strict; ###CPAN module finds files recursively use File::Find; ###Report file: open (OUT, ">InventoryFile.txt"); ###Top-level directory to report on: my $directory = '//InstallBox/C'; ###invoking File::Find, printing path, then filename: find (\&wanted, $directory); sub wanted { print OUT "$File::Find::dir/"; print OUT "$_\n"; } __END__ ################################################# ################################################# #!/usr/bin/perl #CompareReport.pl ###good Perl practice: use warnings; use strict; ###invoke the CPAN module: use List::Compare; ###open some files: open (OUT, ">CDiffs.txt"); open (FILE1, "OldInventory.txt"); open (FILE2, "NewInventory.txt"); ###idiomatic: lowercase each pathname string after loading the arrays— ###(this is a Windows system, might not want to “lc” for Unix): my @file1 = ; $_ = lc for @file1; my @file2 = ; $_ = lc for @file2; ###load the files for List::Compare: my $lc = List::Compare->new(\@file1, \@file2); ###List::Compare features to identify unique elements in each file: my @file1only = $lc->get_Lonly; my @file2only = $lc->get_Ronly; ###talk to the user: print OUT "IGNORING FILES WITH Tmp OR Temp IN PATHNAME.\n"; print OUT "IGNORING FILES IN THE RECYCLE BIN.\n"; print OUT "IGNORING ALL HISTORY FILES.\n"; print OUT "LOWERCASING ALL FILE AND PATHNAMES BEFORE COMPARING.\n"; ###selection criteria is a set of easy Regular Expressions: foreach my $file1(@file1only) { unless (($file1 =~ "tmp") or ($file1=~"temp") or ($file1 =~ "recycler") or ($file1 =~ "history")) { print OUT $file1; } } ###separator is a couple of newlines: print OUT "\n\n"; ###talk to the user about the second file: print OUT "IGNORING FILES WITH Tmp OR Temp IN PATHNAME.\n"; print OUT "IGNORING FILES IN THE RECYCLE BIN.\n"; print OUT "IGNORING ALL HISTORY FILES.\n"; print OUT "LOWERCASING ALL FILE AND PATHNAMES BEFORE COMPARING.\n"; print "\n\n"; ###selection for the second inventory file: foreach my $file2(@file2only) { unless (($file2 =~ "tmp") or ($file2=~"temp") or ($file2 =~ "recycler") or ($file2 =~ "history")) { print OUT $file2; } } __END__ ##############################################