[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] do... while?




Edward M. Perry wrote:
> 
> One might want to mangle the array if every element is going to be
> processed. Next time through the loop can pick up where the previous
> iteration left off. The original problem didn't state that but it 
> might be the case since the solution included it.
> 
> Any clever ways to hold your place in an array without mangling it
> (besides an index of course, that might be considered non-perlish).

Sometimes, an index is the best tool for the job.

But you could get a similar effect -- more flexible but slower --
by pushing the processed items onto a "done" array, after having
shifted them off the "to-do" array:

	while ( @to_do ) {
		my $item = shift @to_do;
		process( $item );
		push @done, $item;
		last if $major_bogosity; # leaves some items in @to_do
	}

Then, at any point, if you want to see the entire list of items,
you simply say

	( @done, @to_do )

which will always look the same, regardless of whether item $i has
been processed.

John Porter


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe