http://www.perlmonks.org?node_id=968493

Hellhound4 has asked for the wisdom of the Perl Monks concerning the following question:

I have been working on and, mostly, off on a project the last couple weeks. I am trying to read a list of file names into one array a list of directory contents into another and compare the two outputting any differences. This is my first project with Perl. I'm getting errors on scope (my masks earlier declaration of variable in same scope) and one that says (Useless use of numeric GE (>=) in void context). Any help on this (or any other errors) appreciated.
#!/usr/bin/perl -w use strict; my $boxEnd; my $pathToDirectory; my @contentsOfDataBase; my @contentsOfDirectory; my @copyOfContentsOfDirectory; my @inDirectoryNotInDataBase; print "First Box?"; chomp (my $boxBegining = <>); print "Last Box?"; chomp ($boxEnd = <>); print "Wait a minute while I look... Lazy..."; open dataBaseContents, "+>", "\\\\SHARESERVER\\DigiOfficeShare\\PerlDe +v\\Database.txt" or die "Aww shit I Broke"; @contentsOfDataBase = <dataBaseContents>; while(<dataBaseContents>) { chomp; push(my @contentsOfDataBase, $_); } close(dataBaseContents); while ($boxEnd >= my $boxBegining, $boxBegining++) { my $pathToDirectory = "\\\\SHARESERVER\\DigiOfficeShare\\PerlDev\\Bo +x $boxBegining"; opendir(my $currentDirectory, my $pathToDirectory) || die "You sure +that exists, dummy?"; while(readdir $currentDirectory) { chomp; push(my @contentsOfDirectory, $_); } closedir $currentDirectory; } @copyOfContentsOfDirectory = @contentsOfDirectory; my %seen; $seen{$_}++ for @contentsOfDataBase; $seen{$_} && undef $_ for @contentsOfDirectory; my %seen2; $seen2{$_}++ for @copyOfContentsOfDirectory; $seen2{$_} && undef $_ for @contentsOfDataBase; @contentsOfDirectory = grep { defined } @contentsOfDirectory; @contentsOfDataBase = grep { defined } @contentsOfDataBase; print "These files have PDFs and no database entries: ", @contentsOfDi +rectory, "\n"; print "These files have database entries and no PDFs: ", @contentsOfDa +taBase, "\n";

Original code restored above (in read more block) by GrandFather

</cuse strict; my $boxEnd; my $pathToDirectory; my @contentsOfDataBase; my @contentsOfDirectory; my @copyOfContentsOfDirectory; my @inDirectoryNotInDataBase; print "First Box?"; chomp (my $boxBegining = <>); print "Last Box?"; chomp ($boxEnd = <>); print "Wait a minute while I look... Lazy..."; open dataBaseContents, "+>", "\\\\SHARESERVER\\DigiOfficeShare\\PerlDe +v\\Database.txt" or die "Aww shit I Broke"; while(<dataBaseContents>) { chomp; push(@contentsOfDataBase, $_); } close(dataBaseContents); while ($boxEnd >= $boxBegining) { my $pathToDirectory = "\\\\SHARESERVER\\DigiOfficeShare\\PerlDev\\Bo +x $boxBegining"; $boxBegining++; opendir(my $currentDirectory, $pathToDirectory) || die "You sure tha +t exists, dummy?"; while(readdir $currentDirectory) { chomp; push(@contentsOfDirectory, $_); } closedir $currentDirectory; } @copyOfContentsOfDirectory = @contentsOfDirectory; my %seen; $seen{$_}++ for @contentsOfDataBase; $seen{$_} && undef $_ for @contentsOfDirectory; my %seen2; $seen2{$_}++ for @copyOfContentsOfDirectory; $seen2{$_} && undef $_ for @contentsOfDataBase; @contentsOfDirectory = grep { defined } @contentsOfDirectory; @contentsOfDataBase = grep { defined } @contentsOfDataBase; print "These files have PDFs and no database entries: ", @contentsOfDi +rectory, "\n"; print "These files have database entries and no PDFs: ", @contentsOfDa +taBase, "\n";