So, I have an array of 2 types of events, and the times they occurred. I need to parse through the array and take teh time of the first Event A, and then find the first Event B after Event A, and calculate the time delta. using a simple grep on the array isn't a viable option because there could be multiple occurrences of Event A before there is an Event B, potentially looking like this:
EVENT A
EVENT A
EVENT B
EVENT A
EVENT A
EVENT A
EVENT B
EVENT A
EVENT B
I had initially thought of using a for loop with a dual index, something that would look kinda like this:
my $i = 0; my $j = $i; for ( $i ; $i <= $#eventlist ; $i++ ){ print "i is $i, j is $j\n"; my ($subj,$date) = split(',',$eventlist[$i]); if ( $subj eq "Event B" ){ while ( $subj ne "Event A" ){ $i++; ($subj,$date) = split(',',$eventlist[$i]); } print "i is $i, j is $j\n"; $j = $i; print "i is $i, j is $j\n"; my ($str,$date1) = split(',',$eventlist[$i]); my ($subj2,$x) = split(',',$eventlist[$j]); while ( $subj2 ne "Event B" ){ $j++; ($subj2,$x) = split(',',$eventlist[$j]);
Is there another iteration method I could be using, or a better set of list processing utilities? I have the Date::Manip module set up for teh date delta calculations, that was not hard. I just can't seem to get the list to process.
In reply to processing a list of events by BluePerlDev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |