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.
i guess my question is the following: is there a better way to search for the newest file in the sub function?#!/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";
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |