Hi Deno,
Lets suppose we had the following :
print "$windmill[$_]\r" for 0..10000;
This would print the array contents for elements 0 to 10000. (The $_
effectively taking the value from the for statement). The \r will print a
carriage return (no line feed) to return the cursor to the start of the
line.
We only have four elements (0..3) in the array, so we want to continually
want to use these.
The statement
print "$windmill[$_ & 3]\r" for 0..10000;
does the same as the previous, but this time we do a bitwise "and" of the
value from the "for" loop with the value 3.
Why 3? you may ask, well lets consider this
Should the value from the for loop be 0 (1st iteration), this has a binary
value 00000000. We perform a bitwise "and" with the value 3 (binary
00000011) - so we have
00000000 (0)
00000011 (3)
--------
00000000 (The result $windmill[0])
For the values 1,2 and 3 we get similar results i.e the resultant would be
1,2 and 3.
When we get to the 5th iteration (value of 4 from the for loop), we can see
the benefit :
00000100 (4)
00000011 (3)
--------
00000000 (The result $windmill[0])
Lets now take a quick look at the 6th (value of 5 from the for loop)
00000101 (5)
00000011 (3)
--------
00000001 (The result $windmill[1])
So, if you follow this process, you will see that the resultant of [$_ & 3]
will be a continual, repeating count of 0,1,2,3,0,1,2,3,0....... and so on -
hence, we cycle through the elements of the array.
Hope this makes sense,
Mark
-----Original Message-----
From: if.then.else [mailto:[EMAIL PROTECTED]]
Sent: 15 June 2001 15:38
To: [EMAIL PROTECTED]
Subject: Re: Spinning Wheel!!!
could someone break this down a little more for me?
> $| = 1;
unbuffer out (right?) - does this mean the program won't wait to finish
before sending character to the screen?
> print "$windmill[$_ & 3]\r" and usleep(50) for 0..10000;
i'm a bit confussed with this print statement.
thanks,
deno
/.
://: emanate records / http://www.emanaterecords.com
../
://: now out : ema008 - solenoid 'services rendered' (cd & lp):
.. .
' ::___ - ' -- - -' -'- -'' ' ' ______------__''