$_ = $"; # copy $", which is a space, to $_, for convenience later $^ = A; # assign 'A', the first label, to $^ &{':'}; # use a symbolic reference to call the sub named : # this starts the process... (see below) sub AUTOLOAD { # the AUTOLOAD sub, called when an undefined subroutine is called print $AUTOLOAD =~ /:+(.?)/s; # $AUTOLOAD holds the name of the undefined subroutine, including +package # i.e. &J calls AUTOLOAD and sets $AUTOLOAD to 'main::J' # find the colons, match the next character, and print it # (when $AUTOLOAD ends in a colon, prints a null string) goto $^++; # goto the label specified by $^ # post-increment $^ for next time } # the rest of the script consists of labels and statements, # in some non-alphabetical order - that's okay, because # the goto calls are in alphabetical order # to make the code easier to follow I'll reorder it starting here &{':'}; # start the process by calling the sub : # a null string is printed, and goto jumps to label A A: &J; # label A: call the sub J # 'J' is printed, and goto jumps to label B B: &u; # label B: call the sub u # 'u' is printed, and goto jumps to label C # this continues for some time... E: &$_; # label E: call the sub [space] with a symbolic reference # ' ' is printed, and goto jumps to label F # etc... Z: &{$/}; # label Z: call the sub [newline] with a symbolic reference # "\n" is printed (thanks to the /s on the regex), # and goto jumps to label AA AA: rjk; # rjk is a bareword, not a subroutine call, # so the script ends
In reply to Re: (SPOILER) autogoto.pl
by chipmunk
in thread autogoto.pl
by chipmunk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |