McMahon has asked for the wisdom of the Perl Monks concerning the following question:
################################################# #!/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 = <FILE1>; $_ = lc for @file1; my @file2 = <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 =~ "recyc +ler") 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 =~ "recyc +ler") or ($file2 =~ "history")) { print OUT $file2; } } __END__ ##############################################
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code review for magazine article?
by tilly (Archbishop) on Apr 08, 2004 at 22:07 UTC | |
|
Re: Code review for magazine article?
by runrig (Abbot) on Apr 08, 2004 at 22:12 UTC | |
|
Re: Code review for magazine article?
by graff (Chancellor) on Apr 08, 2004 at 23:38 UTC | |
|
Re: Code review for magazine article?
by QM (Parson) on Apr 08, 2004 at 22:49 UTC | |
|
Re: Code review for magazine article?
by Grygonos (Chaplain) on Apr 08, 2004 at 20:31 UTC | |
|
Re: Code review for magazine article?
by borisz (Canon) on Apr 08, 2004 at 23:11 UTC | |
|
Re: Code review for magazine article?
by Anonymous Monk on Apr 08, 2004 at 22:20 UTC |