IO-ReadPreProcess

 view release on metacpan or  search on metacpan

lib/IO/ReadPreProcess.pm  view on Meta::CPAN

    $self->ReadBlock($InLine, $code);

    $code->{LastLine}--;	# Remove .done
    $code->{FirstLine}++;	# Remove .sub

    1
}

# $direct is while/until/for
# $arg is loop condition/rest-of-line
# May start: -innn to specify max iterations
# **** THINKS ****
# Loops are found in 2 ways:
# (1) Reading from a {Fd} - ie in getline()
# (2) When in a sub or an enclosing loop
# We always buffer a loop, so the only difference is where/how it is found
# The purpose of this sub is for case (1), need to initiate a buffer creation
# If (1) read into a buffer/code and return a ref to the code
# If (2) set up $code and return that
sub ReadLoop
{

lib/IO/ReadPreProcess.pm  view on Meta::CPAN

		$oframe->{CodeLine} = $frame->{LoopEnd};

                # Evaluate any loop initialisation
                $self->{Math}->ParseToScalar($replay->{Init}) if(exists $replay->{Init});
            }
            $doneDone = 0;

	    # Beware: might be here twice
	    unless($frame->{CondReRun}) {
	    	# Trap run away loops:
            	return $self->SetError("Maximum iterations ($frame->{LoopMax}) exceeded at $frame->{FrameStart}", 1)
                    if($frame->{LoopMax} && ++$frame->{LoopCnt} > $frame->{LoopMax});

            	# evaluation loop expression (not on first time)
	    	$self->{Math}->EvalToScalar($replay->{For3}) if(exists $replay->{For3} and $frame->{LoopCnt} != 1);
            }

            # Evaluate the loop condition - if true keep looping
            my $bool = $self->EvalCond($replay, $dir, $place, $arg);
            next if($frame->{CondReRun});
            $self->closeFrame if( !$bool);

lib/IO/ReadPreProcess.pm  view on Meta::CPAN

Do nothing. The application should check the method C<error> and look at C<$IO::ReadPreProcess::errstr>.

=back

=item PipeOK

Pipes are only allowed with C<.include> if the property C<PipeOK> is true (default false).

=item MaxLoopCount

Loops (C<while>, C<until> and C<for>) will abort after this number of iterations.
The count restarts if the loop is restarted.
A value of C<0> disables this test.

This may be overridden on an individual loop with the C<-i> option.

Default 50.

=item OutStreams

This defines output streams that may be written to by C<.out> and C<.print -o>. The

lib/IO/ReadPreProcess.pm  view on Meta::CPAN


    If also has:
        Type	if/unless
    type	Used in ReadBlock() to check block open/end keywords.

    CpMove	If true: on frame close, any CodeLine to be copied to parent frame.

    ReturnFrom	If true a .return will unwind to here and return to the previous.

    Other properties for loops
    	LoopMax	Max iterations - 0 == no limit - this is copied from code->{LoopMax}
		This is also used to identiy the frame as a loop frame
	LoopCnt	Count of iterations so far
	Loop	Just to note that it is a loop frame

    CondReRun	Rerun the condition in main loop, as: .if .subroutine/.directive
    intDir	Running an internal directive, eg: .if .read var

In the line:
    SubCond	.subroutine args -- when used as a condition, eg: .if .test -f xxxx

CodeBuf - for loops

t/speedTest1  view on Meta::CPAN

.# For loop just to see how long this takes.
.let iter := 10000
.echo Before empty for - iterations \v{iter}
.for -i0 i := 0 ;; i < iter ;; i++
.#.eval i is \v{i}
.done
After for

t/speedTest2  view on Meta::CPAN

.# For loop just to see how long this takes.
.let iter := 10000
.echo Before for loop containing one arith statement - iterations \v{iter}
.let j := 0
.for -i0 i := 0 ;; i < iter ;; i++
.noop
.let j := j + i
.done
.echo After for, j = \v{j}



( run in 2.184 seconds using v1.01-cache-2.11-cpan-71847e10f99 )