Deborah Scott wrote: > > I have a txt data file that has several fields. Two of the fields are start > time and end time (listed in epoch time). > > I need to write a perl program that finds (and prints) events that occur > between midnight "last night" and "midnight tonight." > > First problem: > The date for midnight "last night" and "tonight" will change each day, so > this needs to be some kind of automatic date finder.
use Time::Local; my @today = localtime; # get todays date and time @today[0..2] = ( 0, 0, 0 ); # make it midnight my $lastnight = timelocal( @today ); # convert to epoch time (seconds) my $tonight = $lastnight + 86_400; > Second problem: > How do I find (and then list) only those events that occur TODAY. > These events might start or stop at any time during the month. if ( $event >= $lastnight and $event <= $tonight ) { print "$event happened today."; } > The events that I would list would include ANYTHING that includes "today." > Some might start today and end today and last only an hour. Some might start > two days ago and end next week. This txt file will also list events that > have already started and stopped last month or will start in the future, so > I have to make sure that these are NOT included in "today's" report. my $today = time; # get epoch time if ( $start_event < $today and $end_event > $today ) { print "$event includes today."; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]