Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Clean up and shimmer

by bobf (Monsignor)
on Feb 03, 2005 at 08:06 UTC ( [id://427552]=note: print w/replies, xml ) Need Help??


in reply to Clean up and shimmer

Very cool! It intrigued me enough to try to figure out how it worked - I hope I got close (this is my first attempt at a de-obfuscation):

Spoiler in readmore!

Walking through the code after a bit of reformatting, with some comments:

# Use a hash slice to copy all the keys in the symbol table to %s, # and set each key to undef. @s{keys %::}=(); # Bless a hashref into the current package, thereby creating # AUTOLOAD and DESTROY entries in symbol table. bless{};; # Pull out any keys in %s that are not in %:: (AUTOLOAD and DESTROY), # sort them, and take the second element (DESTROY). # Assign an anonymous sub to the DESTROY typeglob. *{ (sort grep{ !exists $s{$_} } keys %:: )[1] } = sub { $n = 0.5; { # Print a carriage return (sends cursor to beginning of line). # Split the JAPH text into single characters, then for each # character, choose a random number between 0 and 100, # compare to $p and print the character or a space. # Note: as $p increases there is a better chance of # displaying the character (and visa versa). # Question: is the comma in the JAPH text intentional? print "\r", map { rand(100) <= $p ? $_ : ' ' } split //, "Just another Perl hacker,"; # Stop loop when $p < 0 ($n is 0.5 or -0.5, so always < 1). $p < 0 && $n < 1 && last; # Use $n to increase or decrease $p by 0.5 # $p increases from 0.5 to 110.5, then decreases to -0.5 $n *= $p > 110 ? -1 : 1; # change sign of $n if $p > 110 $p += $n; # increase/decrease $p by $n # Use the four-arg form of select (ready file descriptors): # $q is undef, and the timeout value is set to 0.04 sec # This is equivalent to sleep 0.04 with better resolution. select $q, $q, $q, .04; # Redo this block redo } }; # This can be rewritten as 'bless \$0; $| = 1;' # Bless the scalar $0, but since we didn't save a reference to the # newly created object it is immediately destroyed - the DESTROY # method is called on the object, and the sub above is executed. # This can be observed by explicitly declaring an alternative # DESTORY method, or by adding 'print "destorying $_[0]\n";' # to the first line of the subroutine. bless \$|++;
Update: the original code was tweeked, but I don't think it changes this explanation.

Replies are listed 'Best First'.
Re^2: Clean up and shimmer
by davido (Cardinal) on Feb 03, 2005 at 08:23 UTC

    Good job! You were pretty much right on target.

    To answer a few questions...


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://427552]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-19 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found