# 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 \$|++;