kulls:

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.

#!/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; }
A test run on my machine here gives me:

$ ./continuation.pl Next: 600 Another: 600 Another: 700 Next: 700 Next: 800 Another: 800 Next: 900 Another: 900 Another: 1000 Another: 1100 Next: 1000
...roboticus

In reply to Re^3: flushing the data from array by roboticus
in thread flushing the data from array by kulls

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.