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

Fellow monks
I am stumped and am in need of your help. I have a script that will look at a file on two machines, get the stats of it using File::stat and compare the size and mtime to. This works. see here:
# Ray Espinoza # FileCompare.pl # 2/06/02 # This script will compare a file on two different machines ################################################################## use File::stat qw(:FIELDS); my($file, $host1, $host2, $path1, $path2); print "Enter the filename and path which it resides, minus the hostnam +e..etc. /d$/ebayconfig/confighosts.txt .."; print "\n" . "***make sure to use / instead of \ please*********"; chomp($file = <STDIN>); print "Enter the first hostname of the machine you want to compare. "; chomp($host1 = <STDIN>); print "Enter the other host that you want to check file properites. "; chomp($host2 = <STDIN>); $path1 = "//" . $host1 . $file; $path2 = "//" . $host2 . $file; $stat = stat($path1) or die "No File :$!"; if ($st_size & $st_mtime) { $size1 = $st_size; $mtime1 = $st_mtime; } $stat = stat($path2) or die "No File :$!"; if ($st_size & $st_mtime) { $size2 = $st_size; $mtime2 = $st_mtime; } if ($size1 == $size2) { print "File size matches.\n"; }else{ print "$path1 and $path2 have different sizes!\n"; }

I am writing a new script that will create get a directory list of a machine and create a hash of hashes storing the filename as the key and the value variables (size and mtime) as referances. In my code, i have not even got that far because i am not able to "stat" the file as it loops through the directory. It says no such file or directory. I am printing the whole string to see if there is a problem with the directory syntax. Can some one please help. I may be looking to hard at the same code.
#!D:/perl/bin use strict; use File::stat qw(:FIELDS); my ($goodDir, $path, $host1, $host2, $checkDir, $currentFile, $current +File1, $st_size, $st_mtime, $stat, $size, $modtime); my %hashDir1 =(); print "What host would you like to use as template: ?\n"; chomp($host1 = <STDIN>); print "Whats the path you want to use? \n"; chomp($path = <STDIN>); $goodDir = "//" . $host1 . $path; print $goodDir . "\n"; opendir(GD, $goodDir) or die "Can't open $goodDir : $!"; print "what host would you like to examine? \n"; chomp($host2 = <STDIN>); $checkDir = "//" . $host2 . $path; opendir(CD, $checkDir) or die "Can't open $checkDir : $!"; while($currentFile = readdir(GD)) { $currentFile1 = "//" . $host1 . $path . $currentFile . "\n"; print $currentFile1 . "\n"; stat($currentFile1) or warn "No File :$!"); #$stat = stat($currentFile1) or warn "can't stat the file :$!\n"; if ( $st_size & $st_mtime) { $size = $st_size; $modtime = $st_mtime; }else{ print "couldn't stat $currentFile1 : $!"; next; } }

here are a screen shot when i run the script:
C:\scripts\perl>betacompare.pl What host would you like to use as template: ? adams Whats the path you want to use? /d$/prod/perl/debug/ //adams/d$/prod/perl/debug/ what host would you like to examine? jefferson //adams/d$/prod/perl/debug/. No File : at C:\scripts\perl\betaCompare.pl line 28, <STDIN> line 3. couldn't stat //adams/d$/prod/perl/debug/. : //adams/d$/prod/perl/debug/.. No File :No such file or directory at C:\scripts\perl\betaCompare.pl l +ine 28, <S TDIN> line 3. couldn't stat //adams/d$/prod/perl/debug/.. : No such file or directory//adams/d$/prod/perl/debug/bugslayerutil.d +ll No File :No such file or directory at C:\scripts\perl\betaCompare.pl l +ine 28, <S TDIN> line 3. couldn't stat //adams/d$/prod/perl/debug/bugslayerutil.dll : No such file or directory//adams/d$/prod/perl/debug/bugslayerutil.p +db

Thnx in advance.
Ray

Replies are listed 'Best First'.
Re: Using File::stat
by chromatic (Archbishop) on Feb 11, 2002 at 20:56 UTC
    What happens if you flip the slashes around? Might it be that Windows is not recognizing your UNCs as remote file locations when you use forward slashes?

    I'd throw an -e test in there just to make sure.

      It wasn't the "/" "\" thing. i was throwing in a "\n" into the path. i will post final code. got it almost working :) Thanks for your help.
      Ray
(tye)Re: Using File::stat
by tye (Sage) on Feb 11, 2002 at 22:03 UTC

    Well, your second path doesn't end in a / which your code seems to require.

            - tye (but my friends call me "Tye")
Re: Using File::stat
by vek (Prior) on Feb 11, 2002 at 21:41 UTC
    And in the true spirit of TMTOWTDI you could do worse than checking out File::Same at your friendly neighbourhood CPAN.