Cool. Works great. Thanks guys!

-----Original Message-----
From: Chas Owens [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 3:11 PM
To: Balint, Jess
Cc: '[EMAIL PROTECTED]'
Subject: Re: Print Question


On Fri, 2002-04-05 at 14:37, Balint, Jess wrote:
> Hello all. I have been working on this all day. I am trying to print out
> numbers 1 through 10 as this loop progesses. For some reason, it doesn't
> print the numbers until the end of the loop. The $done variable is set to
1
> by the getUniqRand() function once certain conditions are met. Everything
> works fine except the printing. The @random_numbers array is filled up one
> by one from the getUniqRand() function. $opt_s is the number of elements
in
> @random_numbers when it is done. So if I am going to have 10,000 number in
> the array, I want to print a digit each time another 1,000 are added to
the
> array. I believe the algorithm in the if() is correct to do this.
> 
> Is there any reason they wouldn't print until the end?
> 
> do{
>       getUniqRand( $lines, $opt_s );
>       print( ++$fill_pos, " " ) if( scalar( @random_numbers ) % ( int(
> $opt_s / 10 ) + 1 ) == 0 );
> } until $done;

STDOUT is buffered.  That means no text is displayed until a "\n" is
printed or the end of the program (which ever comes first).  You can
change this behavior by setting the $| ($OUTPUT_AUTOFLUSH if you 'use
english;') variable to 1.

do {
        local($|) = 1; #make STDOUT autoflush
        getUniqRand( $lines, $opt_s );
        #I don't like the way this cat is skinned
        #one liners should be on one line
        #print( ++$fill_pos, " " ) if( scalar( @random_numbers ) % ( int(
        # $opt_s / 10 ) + 1 ) == 0 );
        #I would do this
        # % forces scalar context and unless handles the == 0 part
        print ++$fill_pos, " " unless @random_numbers % (int($opt_s/10)+1);
} until $done;



-- 
Today is Setting Orange the 22nd day of Discord in the YOLD 3168
Or is it?

Missile Address: 33:48:3.521N  84:23:34.786W

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to