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

Re: how to delay printing without over working perl

Thread Previous | Thread Next
From:
Chas. Owens
Date:
February 10, 2009 06:24
Subject:
Re: how to delay printing without over working perl
Message ID:
58ce48dc0902100624v267f458eh45221fae1cdbfb@mail.gmail.com
On Mon, Feb 9, 2009 at 18:39, itshardtogetone
<itshardtogetone@hotmail.com> 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
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | 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