zee3b has asked for the wisdom of the Perl Monks concerning the following question:
Hey guys, I'm working on a text parser. I grab the data from the file and push it into an array and then I foreach it, but I'm only looking for specific successive lines when I'm calculating the average. Here's an example. My data file is of this structure
So basically as soon as my regex matches the name Jill or Jack. I want it to pick the score from the 3rd line, any command to add into the if loop? e.gJack Student ID - 12445 Math Score - 45 Jill Student ID - 234254 Math Score - 90 Jack Student ID -12445 Math Score2 - 33 Jill Student ID - 234254 Math Score2 - 10
This way I can average the scores for each student for different tests.if ($line ~= /Jill/) { *pick the score from the sucessive second line*
output = Jack Average 39
Jill Average 50
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Selecting successive lines
by kcott (Archbishop) on Sep 17, 2013 at 04:05 UTC | |
by marinersk (Priest) on Sep 17, 2013 at 10:02 UTC | |
Re: Selecting successive lines
by frozenwithjoy (Priest) on Sep 17, 2013 at 03:52 UTC | |
Re: Selecting successive lines
by davido (Cardinal) on Sep 17, 2013 at 04:35 UTC | |
Re: Selecting successive lines
by ansh batra (Friar) on Sep 17, 2013 at 09:01 UTC | |
Re: Selecting successive lines
by sundialsvc4 (Abbot) on Sep 17, 2013 at 12:50 UTC |
Back to
Seekers of Perl Wisdom