in reply to Sorting through a file with multiple tables and extracting data
When I have to deal with a problem like this one, I like to take “a very awk-inspired approach. (And it should come as no surprise that the Perl language evolved from awk.)
The awk way of doing things basically consists of subdividing the problem into:
Any particular “type of line” might cause us to “do something,” or it might simply contribute variables that will be used later. In this particular example, I see five “potentially interesting” lines:
*-------------------*--------*--------*
Clearly a group-separator. When you see one of these, “forget everything you know.”
% Trm 4 % Trm 5 % % %
Only you really know what this has to do with ...
% Trm7 % Trm % Trm9 % TrmY0 %
... but both of them obviously contribute variable-names.
% -0.063 % -0.4 % 0.0 % 5.6 %
A line of data, to be classified according to the variable-names previously gathered. An obvious application of split().
The general approach is that of a finite-state machine (FSM).