On Tue, Oct 22, 2002 at 02:05:25PM -0700, David Newman wrote:
[snip] 
> I have in input file structured something like this:
> 
> *** Iteration 1
> data,data,data,data,data
> data,data,data,data,data
> data,data,data,data,data
> 
> *** Iteration 2
> data,data,data,data,data
> data,data,data,data,data
> data,data,data,data,data
> 
> *** Iteration 3
> data,data,data,data,data
> data,data,data,data,data
> data,data,data,data,data
> 
> and so on. My goal is to process the data in each iteration separately, so
> the output would look something like:
> 
> iteration_1,result,result,result,result,result
> iteration_2,result,result,result,result,result
> iteration_3,result,result,result,result,result

My suggestion would be to maintain a state variable that describes what
iteration you're on, then when you encounter a new iteration "label" (for
lack of a better term), process the data and change the variable.

For example:

    my(@data, $iteration);
    while (<INPUT>) {
        if (/^\*\*\* Iteration (\d+)$/) {
            process_accumulated_data($iteration, \@data) if @data;
            @data      = ();
            $iteration = $1;

        } else {
            chomp;
            push(@data, $_); # or whatever
        }
    }

That should give you the idea.  You might want to add some sanity checking
$on iteration; if it's undefined, but there has been data processed, you
should probably raise an error.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to