here's what I would do...
################################################# #!/usr/bin/perl #InventoryReport.pl ###Good Perl practice: use warnings; use strict; ###CPAN module finds files recursively use File::Find; ###Open a file for output using the handle OUT open (OUT, ">InventoryFile.txt"); ###Top-level directory to report on: my $directory = '//InstallBox/C'; ###invoking File::Find, printing path, then filename: ##Explain to them what \&wanted means 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 CDiffs.txt for ouput using the handle named OUT open (OUT, ">CDiffs.txt"); ###Open OldInventory.txt for input using the handle FILE1 open (FILE1, "OldInventory.txt"); ###Open NewInventory.txt for input using the handle FILE2 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): #read the entire file into an array (this is called slurping) my @file1 = <FILE1>; #for readability I would re-write '$_ = lc for @file1;' as ##Loop over every line of the array @file1. ##foreach puts the current item in the list in to the ##default variab +le $_. foreach (@file1) { #set the variable to a lowercase version of itself $_ = lc($_); } #Lather rinse repeat comments for file2 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) { #Explain this line .. to even an advanced user who hasn't programmed.. + this could be confusing. 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"; #Same as above ..splain this a bit more.. ###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__ ##############################################
basically.. just be super explicit... avoid using functions that defaulty take $_ as a parameter... for example your original use of lc. You may even (probably bad practice for a magazine article) include an explicit version (haha) and a condensed version...to show how powerful (and/or confusing) perl can be when written in a golfing fashion. Code looks alright.. but that's with my limited experience and no use of File::Find ever ... and also no List::Compare use.

Grygonos

In reply to Re: Code review for magazine article? by Grygonos
in thread Code review for magazine article? by McMahon

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.