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

Re: how to delay printing without over working perl

Thread Previous | Thread Next
Chas. Owens
February 10, 2009 06:24
Re: how to delay printing without over working perl
Message ID:
On Mon, Feb 9, 2009 at 18:39, itshardtogetone
<> wrote:
> 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;

It seems odd to me that you wish to delay printing of sequential
lines.  What benefit do you seek by doing so?

If you absolutely must avoid outputting data until after the loops are
finished, you should probably write your output to a file and then
display the file after the loop.

Chas. Owens
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About