hello monks, i am here to seek wisdom from you. i have two direcotries, each containing pictures. the regional directory is updated every 5 minutes, the watch directory is updated every 15. what i am trying to do is find the newest file in each directory and take those files and use image magik to create a third immage. what i have works for some but is very inconsistant, for example my code will sometimes miss the regional files when it's time matches the watch files. meanning if the regional file comes in at 103500 (HHMMSS) and watch file comes also at 103500, then sometimes it will skip this one and it will wait untill it sees 104000 regional file then it will use the 103500 watch file and merges them. again this only happens sometimes, the code works for the most part. I have no clue how to fix it, and i looked at it for soo long my eyes cant pick pu any thing. any help is much appritiated. P.S in the function that finds the newest fils uses the ctime 10. i tried using atime8, mtime9. ctime has been the best option so far. here is my code.

#!/usr/bin/perl use strict; use warnings; use File::Find; use vars qw/%files_watch/; use vars qw/%files_regional/; ####################################################### sub findNewestFiles { my $element = $File::Find::name; return if (!-f $element); SUB fucntion that finds the newst f +ile $files_watch{$element} = (stat($element))[10]; $files_regional{$element} = (stat($element))[10]; } ####################################################### ####################################################### # MAIN ####################################################### my $image_magick_exe = "composite.exe\""; my $pic_dir ="C:\\eterra\\eterravision\\weather"; my $watch_dir = "C:\\eterra\\eterravision\\weather\\watch"; my $regional_dir = "C:\\eterra\\eterravision\\weather\\regional"; open (OUT, ">>names.txt")|| die "did not open file\n"; ################################################################# find(\&findNewestFiles, $watch_dir); my $newestfile_watch; my $time_watch = 0; while(my ($t1, $t2) = each(%files_watch)) { if ($t2 > $time_watch) { $newestfile_watch = $t1; $time_watch = $t2; } } $time_watch = localtime($time_watch); ################################################################# ################################################################## find(\&findNewestFiles, $regional_dir); my $newestfile_regional; my $time_regional = 0; while(my ($t3, $t4) = each(%files_regional)) { if ($t4 > $time_regional) { $newestfile_regional = $t3; $time_regional = $t4; } } $time_regional = localtime($time_regional); #print"$newestfile_regional\n"; ################################################################## $newestfile_watch=~s/\//\\/g; #replacing the "/" in the file path + to "\"" $newestfile_regional=~s/\//\\/g; #print "$newestfile_watch\n"; my @temp = split(/_/, $newestfile_regional); my $type = $temp[0]; my $date = $temp[1]; my $time = $temp[2]; #print "$date\_$time\n"; my $check= "$pic_dir/radarwatch\_$date\_$time"; if ($newestfile_watch eq $newestfile_regional){ $newestfile_regional =~ s/watch\\watchwarnings/regional\\regionalr +adar\_$date\_$time/; } unless (-e $check) { system("\"$image_magick_exe \"$newestfile_regional\" \"$newestfile +_watch\" \"$pic_dir\\radarwatch\_$date\_$time\""); print"file created\n"; } print OUT "regional is [$newestfile_regional]\n"; print OUT " watch is [$newestfile_watch]\n\n\n"; print OUT "END OF LINE\n";
i guess my question is the following: is there a better way to search for the newest file in the sub function?

In reply to Finding Two newest files, in two seperate directories and merging them. by domali

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.