Ah, there's nothing like a bit of recursion to add some obfuscation. A really, really clever obfu. First you need to understand what/how this code prints:
You can see this prints _Just by virtue of the fact that print uses $_ if no value is specified. As there is no value to the left of the concatenation that is what is used. Here is the decon:$_ = "_"; print; tr/_/J/; print .''; tr/J/u/; print .''.tr/u/s/; print .tr/s/t/; print .tr/t/ /;
# declare some protos so we can call the subs J A P and H # without an & prefix or () suffix -> ie as barewords. sub J;sub A;sub P;sub H; # {s __\__ == J } is the same as: s//_/; J; # the s//_/ substitutes '_' into $_ # and the == J checks for equality to # the return value of the subroutine J # called as a bareword by virute of the # prototyping. The equiality is false BTW :-) # effectively we just call sub J sub J { print # print . # concatenate y:s:S: # tr/s/S/ important because label 's' does not exist . # concatenate goto$_; # go to '_:' label which follows _: # label y:_:J: # tr/_/J/ change value in $_ to 'J' . # concatenate J; # recursively call sub J but now $_ = 'J' # so goto $_ goes to J: below J: # more of the same..... y:J:u: # change label marker in $_ to 'u' . J; # recurse u: # label y:u:s: # change label 'u' to 's' which does not exist # but first tr before goto changes $_ 's' to 'S' # which does exist below so more of the same! . J; # recurse S: # label y:S:t: # change label marker in $_ to 't' . J; # recurse t: # label y:t: : # change label marker in $_ to ' ' == A # call the next sub A via a bareword } sub A { print. y: :_:.goto$ # change $_ from ' ' as left in the last sub # to '_' allowing us to find the label '_:' _;_:y:_:a:. # same theme repeated A;a:y:a:n:. A;n:y:n:o:. A;o:y:o:t:. A;t:y:t:h:. A;h:y:h:e:. A;e:y:e:r:. A;r:y:r: : == P } sub P { print. y: :_:.goto$ # as above _;_:y:_:P:. P;P:y:P:e:. P;e:y:e:r:. P;r:y:r:l:. P;l:y:l: : == H } sub H { print. y: :_:.goto$ # as above _;_:y:_:h:. H;h:y:h:a:. H;a:y:a:c:. H;c:y:c:k:. H;k:y:k:e:. H;e:y:e:r:. H;r:y:r:_:. # final transformation changes $_ to '_' print;exit} # so we print symetrical '_' and exit
Recursion and goto what a choice combo to make spagetti
cheers
tachyon
In reply to Re: goto still considered harmful
by tachyon
in thread goto still considered harmful
by MeowChow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |