I need your help to find the best algorithm for my task. The task is very simple, read lines form a file and check lines which the "Interval Date" contains a set of Hours (The Interval Date won't be greater than 24 Hours).
The file is in the form:
The "pseudo code" should be something like that:Start_Time | End Time | TEXT 2009-07-22 08:00:00|2009-07-22 08:00:00|blablalblabla 2009-07-22 01:00:00|2009-07-22 01:00:00|blablalblabla 2009-07-22 08:00:00|2009-07-22 21:00:00|blablalblabla 2009-07-22 23:00:00|2009-07-23 00:00:00|blablalblabla 2009-07-22 23:00:00|2009-07-23 02:00:00|blablalblabla
The output for the sample file should be (corrected after graff comments):my @hours (1, 11) ; # Hours to check open (FILE,"file.txt") or die "$!;"; <FILE>; # Skip first line while (<FILE>){ # Correction after [ack] comment chomp; my ($start_date,$stop_date,$text) = split '|'; print "\nInterval $start_date - $stop_date\n"; foreach my $hour(@hours){ if( ($start_date to $stop_date) contains $hour){ # pseudo code print "Hour $hour: Match"; }else{ print "Hour $hour:Not Match"; } } close(FILE);
Interval 2009-07-22 08:00:00 - 2009-07-22 08:00:00 Hour 1 :Not Match Hour 11:Not Match Interval 2009-07-22 01:00:00 - 2009-07-22 01:00:00 Hour 1 :Match Hour 11:Not Match Interval 2009-07-22 08:00:00 - 2009-07-22 21:00:00 Hour 1 :Not Match Hour 11:Match Interval 2009-07-22 23:00:00 - 2009-07-23 00:00:00 Hour 1 :Not Match Hour 11:Not Match Interval 2009-07-22 23:00:00 - 2009-07-23 02:00:00 Hour 1 :Match Hour 11:Not Match
Any help will be helpful.
In reply to Check if Date interval contains Hour X by gulden
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |