Where do I even start?
Set total=0. Get the first line. If that line is a >, then move to the next line. Set subtotal[0]=0. Take the first number and put it into var[0], and the second number, and put it into var[1]. Move to the next line, and put the first number into var[2] and the second number into var[3]. Calculate the distance using var[0], [1], [2], [3]. Add the distance to subtotal[0]. Set var[0]=var[2] and var[1]=var[3]. Move to the next line and put the first number into var[2] and the second number into var[3]. Unless the next line starts with a >, then add subtotal[0] to total...
There's so many different places where a different looping process starts, or overlaps with another one. I'm beginning to wonder if this is beyond me.
Well, you did already describe one way that would (probably) work...
This is what I'd do (in C, I don't know perl or python):
I'd have a 'point' structure, with 'x' and 'y' components. A 'distance' function that returns the distance between 2 given points. A 'previous_point' point, which will store NULL when we're at the beginning of a segment. A 'current_point' point. Then,,
I'd have a 'string' variable - a 7-char array (7 should be big enough..), which would store the current "fragment" of the input file we're parsing, retrieved with the fscanf function. Then you can compare string[0] to '>' so you can set 'previous_point' to NULL,
else you can use the atoi function on 'string' and store the result in 'this_point.x' and then do something like 'fscanf (input_file, "%d", &this_point.y)' and then this_point is populated. And then check if previous_point is NULL, if it is then do nothing, otherwise do a 'total += difference (previous_point, this_point)' job. Then 'previous_point = current_point' And... If all of
is happening in a while (string[0] != EOF) type-loop (string being defined outside the loop (I completely messed that up)) it should work. Hopefully.
Alot of the specifics there I'm unsure of though, it's only after I'm in the write-compile-fix mood I can be sure of anything, with C.
If that's completely wrong, if it just doesn't work, it's the kinda thinking I'd start off with, anyhow.
(what a mess of a post, but I hope you got the idea..)