Your array data doesn't exist until the loop completes.
Perhaps you mean you want to remove the explicit loop? If so, you might try using map to generate your series in a single statement. However, you'll still have your memory problems.
Or maybe you're interested in a continuation? That is, a function that you can just get the next value from when you want it? That would let you work with your data without having to store it in an array.
A test run on my machine here gives me:#!/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; }
...roboticus$ ./continuation.pl Next: 600 Another: 600 Another: 700 Next: 700 Next: 800 Another: 800 Next: 900 Another: 900 Another: 1000 Another: 1100 Next: 1000
In reply to Re^3: flushing the data from array
by roboticus
in thread flushing the data from array
by kulls
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |