C
ChristopherSimone
I am working on a hashing program that reads a .ini file and creates a
md5hash of any directory listed within. I am checking properly if the
file still exists and checks the hash and if a new file has been
created and there is no saved hash. What I am trying to fix now is if
I have a stored hash of a file and that file is no longer in the place
it should. Listed below is my code and what I am seeing.
sub missing
{
print "ok1\n";
my $newOD;
open $newOD, $digestdir or die "Cannot open digestdir: $!\n";
#digestdir is where the md5 digest files are
#stored
print "ok2\n";
while( defined( my $x = readdir $newOD ) )
{
print "inside";
my $count = 0;
if( -f "$digestdir/$x" )
{
print "$x\n";
# %hashed is a hash of all my md5s. It is populated with file/hash
pairs from the original directory.
# If I have a file in my digest directory that matches up with one of
the pairs then the program will not worry about
# it. If it doesn't find a match that means a file that had a hash no
longer exists.
foreach my $j (keys %hashed)
{
if( $j eq "$digestdir/$x" )
{
$count++;
}
}
}
if( $count == 0 )
{
print "This file no longer exists: $x\n";
}
}
print "outside\n";
close $newOD;
}
When I run the program I get the following output:
ok1
ok2
outside
The program seems to skip the while loop all together (I am guessing
that my condition is not defined), but I use the exact same code in a
similar manner in another section that seems to work fine. Maybe it
has something to do with the scope of the directory handle, but I made
sure that it was local to the sub and not used elsewhere in the
program. Any advice?
md5hash of any directory listed within. I am checking properly if the
file still exists and checks the hash and if a new file has been
created and there is no saved hash. What I am trying to fix now is if
I have a stored hash of a file and that file is no longer in the place
it should. Listed below is my code and what I am seeing.
sub missing
{
print "ok1\n";
my $newOD;
open $newOD, $digestdir or die "Cannot open digestdir: $!\n";
#digestdir is where the md5 digest files are
#stored
print "ok2\n";
while( defined( my $x = readdir $newOD ) )
{
print "inside";
my $count = 0;
if( -f "$digestdir/$x" )
{
print "$x\n";
# %hashed is a hash of all my md5s. It is populated with file/hash
pairs from the original directory.
# If I have a file in my digest directory that matches up with one of
the pairs then the program will not worry about
# it. If it doesn't find a match that means a file that had a hash no
longer exists.
foreach my $j (keys %hashed)
{
if( $j eq "$digestdir/$x" )
{
$count++;
}
}
}
if( $count == 0 )
{
print "This file no longer exists: $x\n";
}
}
print "outside\n";
close $newOD;
}
When I run the program I get the following output:
ok1
ok2
outside
The program seems to skip the while loop all together (I am guessing
that my condition is not defined), but I use the exact same code in a
similar manner in another section that seems to work fine. Maybe it
has something to do with the scope of the directory handle, but I made
sure that it was local to the sub and not used elsewhere in the
program. Any advice?