in reply to *Poof *, and it's gone.
Line by line:$g ='* * * * * Just another Perl hacker. * * * * *'; $t=length $g; sub h{ select $9,$8,$7,pop } $|++; $r="\r".' 'x$t; print $g; h(1); { h(.15); print " $r\r@{[' 'x(($t-length $g)/2)]}$g"; do { die"$r\n" }unless $g=~s/(.)(.)/($1,$2)[rand(2)]/gex; redo }
Sets string $g to the specified value, and sets $t to 48, the length of $g. So far so good.$g ='* * * * * Just another Perl hacker. * * * * *'; ; $t=length $g;
4-arg select does some funky stuff with filehandles, but if the first 3 arguments are undef (which they are here), it simply sleeps for the time (in seconds) specified by the fourth argument, which, in this case, is the first argument for h. So h sleeps for any number of seconds that its argument specifies.sub h{ select $9,$8,$7,pop }
Unbuffer the output, so characters show up on screen right as perl prints them.$|++;
Sets $r to a return character, followed by 48 spaces (the length of our JAPH string). Call this our clear string. A carriage return is NOT a newline. It brings the carriage to the beginning of a line but it does not advance the line. Thus, this string is effectively a "line clearer". Since the maximal string is only 48 characters, this string clears our line for all intents and purposes. Then, print the JAPH string.$r="\r".' 'x$t; print $g;
Beginning the meat of the obfu here, we pause for one second, then begin a bare block which we will redo until certain conditions are met.h(1); { h(.15); print " $r\r@{[' 'x(($t-length $g)/2)]}$g";
Let's examine the condition first: for every 2 characters in our japh string, we delete one. It now has a length of 48/2 = 24. If there are fewer than 2 characters left, then we die and print our clear string followed by a newline. Then, we go back to the blocks beginning to do it over. Let's look at the print statement for this next loop to get a feel for how it works:do { die"$r\n" }unless $g=~s/(.)(.)/($1,$2)[rand(2)]/gex; redo
Now, we print our control string and a return. Nothing new. But now, $t (the original length, 48) and length $g (the current length, 24), differ by 24, making it necessary to print 12 spaces at the beginning of the JAPH string. This has the effect of centering the string:print " $r\r@{[' 'x(($t-length $g)/2)]}$g";
Since the orignal string was 48 characters, printing 12 spaces at the beginning of the string keeps 24 characters centered in this 48 character "box". Rinse and repeat, halving the number of characters each time.____________xxxxxxxxxxxxxxxxxxxxxxxx____________
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SPOILERS Re: *Poof *, and it's gone.
by davido (Cardinal) on Feb 13, 2004 at 05:39 UTC |