Thank you to all who helped. Your guess was indeed correct I was looking at the dir attempting to see what file was newest and then output that file name. I have the perl working, the code may not be the nicest but it works. I realised I was not keeping the old compare time when looking at graff's example. I unfortunately cannot use a lot of modules. We are running an older version of perl at work and they refuse to update. I can't even use NET::Telnet
Here it is as it works followed by the output:
#use strict;
my $comparetime="0";
sub compare;
##defines locations to look for files
$Clinrxdir="D:\\StoreAccess\\shared\\sup shared\\";
##reads DIR
opendir(DIR,$Clinrxdir);
@Files= readdir(DIR);
closedir(DIR);
#for every file retured do the following
foreach $cpupdate (@Files){
##if the file starts with CP_ checks it's timestamp
if($cpupdate =~ m/\s*cp_/i){
##I did not write this section I was using code I read up on using goo
+gle and found in other various
##scripts we used, for me the fact it broke it down in to a simple int
+ style var made life easier.
my $m_time = (stat($Clinrxdir.$cpupdate))[9];
my ($i_wday, $i_month, $day, $year) = (localtime($m_time))[6,4,3,5];
##prints what files where found and time stamps
print "Timestamp for " . $cpupdate . " " . $m_time ."\n";
##Attempting to use this sup to compare time stamps and change the $fi
+le var to the one with most recent
##stamp
compare($m_time);
}
}
##$file is pulled from the compare sub
print "The oldest file= " . $file . "\n";
print "The time stamp for this file is " . $oldcomp . "\n";
system("pause");
##this was meant to work in the following manner: look at time stamp.
+if it's older than the one
##currently stored do nothing, if it's newer change $file to be the fi
+le name of the newer file.
##this is where I realised my folly thanks to graff's code.. I was not
+ keeping anything to compare to
##other than the new string
sub compare($){
local( $string ) = shift;
if($comparetime > $oldcomp){
$file=$cpupdate;
$oldcomp=$string;}
else{$comparetime = $string;}
}
Timestamp for CP_APR09.exe 1241465790
Timestamp for CP_FEB09.exe 1236031283
Timestamp for CP_JUL09.exe 1249498031
Timestamp for CP_JUN09.EXE 1247593421
Timestamp for CP_MAR09.EXE 1238771856
Timestamp for CP_MAY09.EXE 1244056821
The oldest file= CP_JUL09.exe
The time stamp for this file is 1249498031
That is as the output looks when returned in perl
once again thank you for your help
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.