gulden has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check if Date interval contains Hour X
by ikegami (Patriarch) on Jul 23, 2009 at 18:58 UTC | |
by alexm (Chaplain) on Jul 23, 2009 at 21:40 UTC | |
by ikegami (Patriarch) on Jul 23, 2009 at 21:50 UTC | |
by alexm (Chaplain) on Jul 23, 2009 at 22:41 UTC | |
|
Re: Check if Date interval contains Hour X
by alexm (Chaplain) on Jul 23, 2009 at 18:42 UTC | |
by ikegami (Patriarch) on Jul 23, 2009 at 19:21 UTC | |
by alexm (Chaplain) on Jul 23, 2009 at 20:08 UTC | |
by ikegami (Patriarch) on Jul 23, 2009 at 20:26 UTC | |
by alexm (Chaplain) on Jul 23, 2009 at 21:33 UTC | |
| |
|
Re: Check if Date interval contains Hour X
by graff (Chancellor) on Jul 24, 2009 at 03:31 UTC | |
by gulden (Monk) on Jul 24, 2009 at 09:42 UTC | |
|
Re: Check if Date interval contains Hour X
by ack (Deacon) on Jul 24, 2009 at 04:46 UTC | |
by gulden (Monk) on Jul 24, 2009 at 09:26 UTC | |
|
Re: Check if Date interval contains Hour X
by gulden (Monk) on Jul 24, 2009 at 10:08 UTC |