BluePerlDev has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: processing a list of events
by BrowserUk (Patriarch) on Apr 30, 2015 at 19:54 UTC | |
|
Re: processing a list of events
by davido (Cardinal) on Apr 30, 2015 at 19:01 UTC | |
by Laurent_R (Canon) on Apr 30, 2015 at 22:36 UTC | |
|
Re: processing a list of events
by GotToBTru (Prior) on Apr 30, 2015 at 20:35 UTC | |
|
Re: processing a list of events
by Laurent_R (Canon) on Apr 30, 2015 at 21:38 UTC | |
|
Re: processing a list of events
by jeffa (Bishop) on Apr 30, 2015 at 22:57 UTC | |
|
Re: processing a list of events
by kroach (Pilgrim) on Apr 30, 2015 at 22:37 UTC | |
|
Re: processing a list of events
by Anonymous Monk on Apr 30, 2015 at 21:03 UTC |