in reply to iter
First, you cannot have more than one active iterator in your program at once.
Second, you used a lot of code!
You might prefer this object-oriented approach. The interface is almost the same as yours, but the code is only six lines long:
sub iterstart { my @a = @_; return sub { my $n = shift; $n = 1 unless defined $n; return splice @a, 0, $n; }; } @data = qw(1 fee 2 fee fi 3 fee fi fo 4 fee fi fo fum 1 fin); my $iter = iterstart @data; while (my ($len) = $iter->()) { push @lol, [$iter->($len)]; } use Data::Dumper; print Dumper \@lol;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: iter
by MeowChow (Vicar) on Mar 27, 2001 at 22:25 UTC | |
by MeowChow (Vicar) on Mar 28, 2001 at 07:50 UTC |