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";

In reply to Question of scope and syntax by Hellhound4

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.