*headsplode*

Ok. So Perl has a remarkably plastic synax that allows you to “think” (IE: code in) the syntaxes of C, awk, shell, FORMs and a few other things. It’s a subtle thing, but incredibly useful for people who just want to get things done. The wide variety of acceptable syntaxes can give some language purists hives, but it was an intentional decision to err on the side of being useful.

From a language parsing perspective, though, it’s nightmarish. Let me show you how:

whatever / 25 ; # / ; die “this dies!”;

This nugget of pain is from Randal Schwartz.

If the function “whatever” is nullary (that is, takes no arguments), the first statement is a division in void context, and the rest of the line is a comment.

If “whatever” takes an argument, Schwartz’s Snippet parses as a call to the whatever function with the result of a match operator, then a call to the die() function.

*headsplode*

(This example was shamelessly stolen from the formal proof that Perl cannot be parsed: http://www.perlmonks.org/?node_id=663393 )

Leave a Response