News for hackers. Stuff that matters.
Re:Perl code that is syntactically correct only on Fridays by manojlds on Wednesday February 16, 2022 @09:04AM (#30360055)
That's standard runtime issue right? This is syntax error at compile time.
Re:Perl code that is syntactically correct only on Fridays by dhosek on Wednesday February 16, 2022 @10:07AM (#30360902)
Kind of sort of. The catch here is that because runtime is compile time with Perl, it's not exactly the same. Looking at the code, it's kind of like having something like

    #if (some C preprocessor expression that's true on Fridays
       printf("Hello world!);
    #else
       printf;
    #fi
(although it's been long enough since I've written C that I don't know if (a) there exists a C-preprocessor instruction as per the above, (2) if the compiler will notice errors in the unexecuted branch of an #if and (iii) if printf; would give a syntax error).

Another equivalent piece of code could be something along the lines of the JS

    if (today_is_friday()) {
      eval("2+2")
    }
    else {
      eval("--2abc")
    }
Re:Perl code that is syntactically correct only on Fridays by garaetjjte on Wednesday February 16, 2022 @11:38AM (#30362159)
>(a) there exists a C-preprocessor instruction as per the above

There's no day-of-week but you could cause mayhem with __DATE__

>(2) if the compiler will notice errors in the unexecuted branch of an #if

Compiler only gets to see preprocessor output, it won't.

>if printf; would give a syntax error

Perhaps surprisingly but no, it's just statement without effect (containing expression returning function pointer to printf).

Re:Perl code that is syntactically correct only on Fridays by nousermane on Wednesday February 16, 2022 @11:47AM (#30362273)
> you could cause mayhem with __DATE__

It takes some patience, but people do try: https://stackoverflow.com/questions/11697820#16472369