As for how this works, first notice that Perl regular expressions are much more powerful than traditional regular expressions: you can, forexample, execute Perl code inside a regular expression, allowing you to solve problems once thought "impossible" to solve with regexps, such as matching arbitrarily deeply nested parens ... or executing a complete 99 bottle of beer program inside a regexp. :-)
Second, notice that dynamic languages (such as Perl and many others) allow you to build a code string from an expression, then compile and execute it on the fly. In this case, the rather long expression is a series of
bit-twiddling operations joined together with the string concat operator (.) producing a 99 bottle of beer program string.
BTW, as this is a constant expression, the Perl parser sees it more clearly than the human reader (as you will discover if you run perl -MO=Deparse beer.pl).
Partager