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

In reply to Using File::stat by RayRay459

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.