RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:
# 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"; }
#!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; } }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using File::stat
by chromatic (Archbishop) on Feb 11, 2002 at 20:56 UTC | |
by RayRay459 (Pilgrim) on Feb 12, 2002 at 00:17 UTC | |
|
(tye)Re: Using File::stat
by tye (Sage) on Feb 11, 2002 at 22:03 UTC | |
|
Re: Using File::stat
by vek (Prior) on Feb 11, 2002 at 21:41 UTC |