David Newman wrote:
>
> Clueless newbie question about iterating over selected regions of a file.
>
> 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
>
> I have a subroutine that works fine for processing a file with just one
> iteration. BUT I am totally stuck on handling multiple iterations. The
> following does NOT work:
>
> while (<INPUT>) {
> if (my $tmp =~ /Iteration 1/) {
> until ($tmp =~ /Iteration 2/) {
> if (/^(.*)$/sm) {
> push (@aa, $1);
> }
> }
> next;
> }
>
> # do stuff to $aa[whatever] here
> }
>
> any suggestions gratefully accepted
If your data are separated by blank lines then you can use paragraph
mode to read each interation.
$/ = ''; # set paragraph mode
while ( <INPUT> ) {
s/\A.*?Iteration \d+.*\n//; # remove 'Iteration \d+' line
push @aa, split /\n/;
# do stuff to $aa[whatever] here
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]