#!/usr/bin/perl -w use strict; use warnings; # Build a continuation to return the series of interest sub make_a_continuation { # Variables the continuation uses my $max = shift; my $first = 1; # Return an anonymous function ref to generate next item return sub { $first++ * 100 + 300 + 200; } } # Build a couple continuations my $get_next = make_a_continuation(50); my $get_another = make_a_continuation(100); # None of the data elements in the two series exists yet! You'll # have to create them as you need them by calling the appropriate # continuation, e.g. &$get_next. for my $loop (1..100) { # Randomly create & print items from the series print &$get_next . "\n" if rand(5) < 2.0; print &$get_another . "\n" if rand(5) < 3.5; } #### $ ./continuation.pl Next: 600 Another: 600 Another: 700 Next: 700 Next: 800 Another: 800 Next: 900 Another: 900 Another: 1000 Another: 1100 Next: 1000