how to delay printing without over working perl

how to delay printing without over working perl

am 10.02.2009 00:39:08 von sunnyIsland

------=_NextPart_000_0007_01C98B52.A8493940
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

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;

------=_NextPart_000_0007_01C98B52.A8493940--

Re: how to delay printing without over working perl

am 10.02.2009 14:45:29 von David Shere

On Tue, 2009-02-10 at 07:39 +0800, itshardtogetone wrote:
> I then wonder are there any other better ways for me to do this.

If you need a delay in your code, use the sleep command:
sleep 5; # five second delay




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: how to delay printing without over working perl

am 10.02.2009 15:24:01 von chas.owens

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 printi=
ng of "First loop" and "Second loop" by pushing them into @printer which wa=
s 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.

--=20
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: how to delay printing without over working perl

am 11.02.2009 13:07:41 von sunnyIsland

------=_NextPart_000_0032_01C98C84.64E71F90
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

----- Original Message -----=20
From: "Chas. Owens"
To: "itshardtogetone"
Cc: beginners@perl.org

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.

Yes, for sequential reasons, I need to output data only after the loops. =
Thanks for the advice everybody, I will save to a file and then recall =
it later.
Thanks

------=_NextPart_000_0032_01C98C84.64E71F90--