Is the proof, that perl is capable of this behaviour?! I don't get it - what is the point?
I read all the comments and still don't get it. What am i missing?
Is the proof, that perl is capable of this behaviour?! I don't get it - what is the point?
I read all the comments and still don't get it. What am i missing?
It's not a runtime error but a compile time error. Because yes otherwise I would agree that it's doable easily in every single language.
enum timestamp = __TIMESTAMP__;
void main() { pragma(msg, timestamp[$-6..$-5]); auto a = 4; static if(timestamp[$-6..$-5] == "4") { auto a = 7; } }
What will happen when the command is `perl -c friday.pm`?
Note that the error message is "friday.pm had compilation errors, so yes, there's a compilation phase. It's not compiled to the machine code, though.
What's being noted is the degree of flexibility that Perl has with respect to its execution environment.
Though if you include preprocessors, you expand the number of languages for which you can do something similar.
f/1;#/+
is parsed differently depending on the day. On Friday it's [ "f", "/1;#/", "+" ]
Other days it's parsed as [ "f", "/", "1", ";" ].Perl is parsing /1;#/ is a regex based on whether f takes arguments. Otherwise it parses the slash as division and then the hash is a comment.
Another example could be:
foo() {
some_func / 1;#/; die "It died"
foo
}
Which depends on some_func to not halt. some_func could come from another file, set by whoever invokes the current file. Whatever, it's determed at runtime.This leads to a proof that perl is a actually impossible to parse.
https://www.perlmonks.org/?node_id=663393
Which means you can't do a lot of static tooling on perl because you just can't analyses the source accurately. (Compared to say python, which parses source before running it)
they only follow the non-defective side one day a week
because perl doesn't forward analyze, it never sees the error on other days, and doesn't fail
the presentation is false. this code is always wrong. it's just that the bug is only visible under certain conditions.