sub _ { print "perl "; ::->() }
sub :: { print "hacker\n"}
sub ::1 { _ print "another "}
sub ::0 { print "just " }
1->(%1->());
Since
%1 is empty it evaluates to 0 in scalar context, so the last line is really
1->(0->());.
- 0->() prints "just " and returns 1
- 1->(1) prints "another " and calls _(1)
- _(1) prints "perl " and calls '::'->()
- '::'->() prints "hacker\n" and returns 1
sub :: { print "hacker\n"}
sub _ { print "perl "; ::->() }
sub ::1 { _ print "another "}
sub ::0 { print "just " }
1->(%1->());
In this version the subroutine :: has already been declared when the parser finds the bareword :: in the definition of _. The bareword :: is therefore interpreted as a subroutine call instead of a string. This means that ::->() is equivalent to '::'->()->(). The first subroutine call prints "hacker\n" and returns 1, so the second subroutine call is equivalent to 1->(), which starts over again at "another ".