develooper Front page | perl.beginners | Postings from February 2009

how to delay printing without over working perl

Thread Next
From:
itshardtogetone
Date:
February 9, 2009 15:39
Subject:
how to delay printing without over working perl
Message ID:
COL0-DAV56C321969B805E90E2C91DB7BC0@phx.gbl
Hi,
Looking at the script below, I wish to print out "line 1" first, which is after the while loop, then followed by "First loop", and then "Second loop", henceforth I have the script below. What I did was to hold on the printing of "First loop" and "Second loop" by pushing them into @printer which was then printed out after printing "line1.

The problem is, if there are many iterations of the while loops, then the contents of @printer becomes very large before its printed out and this I fear may take up a lot of memory. I then wonder are there any other better ways for me to do this.
Thanks

#### scripts #######
#!/usr/bin/perl
use warnings;

while ( 1 ){
    push @printer,"First loop\n";
    while ( 1 ){
        push @printer,"Second loop\n";
        last;
    }
    last,
}

print "line 1\n";
print @printer;

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About