Earlier quoted context omitted.
> I have written code that only works in winter because of daylight saving times and some unfortunate date conversions Not sure where you are located, but this can be particularly bad in the UK where winter time happens to coincide with UTC.
Let's be pedantic about this, because this is one of the very few areas where pedantry matters: GMT ("British Winter Time") is NOT UTC, and it can differ from UTC up to 0.9 seconds. GMT is a time zone (corresponding to UT1). UTC is a time standard.
Perl code that is syntactically correct only on Fridays
21–30 of 233 posts
Re: Perl code that is syntactically correct only on Fridays
#22Earlier quoted context omitted.
> I have written code that only works in winter because of daylight saving times and some unfortunate date conversions Not sure where you are located, but this can be particularly bad in the UK where winter time happens to coincide with UTC.
Let's be pedantic about this, because this is one of the very few areas where pedantry matters: GMT ("British Winter Time") is NOT UTC, and it can differ from UTC up to 0.9 seconds. GMT is a time zone (corresponding to UT1). UTC is a time standard.
Re: Perl code that is syntactically correct only on Fridays
#23I have written code that only works in winter because of daylight saving times and some unfortunate date conversions, but having a temporary correct syntax is really a new high.
Re: Perl code that is syntactically correct only on Fridays
#24This leverages Perl's BEGIN block which runs before the main part of the code. I suppose the same fun could be had in other languages: if day_of_week is "Friday" eval(piece_of_incorrect_code) else do_sane_operation
Most other languages would require `eval` and having incorrect code as syntactically correct string literal. But because Perl is parsed as it is executed, incorrect code raises syntax error only when it is reached by execution.
That's not generally true for Perl. The BEGIN block is used to get in that state here. "Some incorrect code raises syntax error only when it is reached" is true.
It's generating this on Fridays:
&f() / 1;
And this on other days: f(/1;#/+);
If you run the same code, but without BEGIN blocking the assignment to *f, it isn't incorrect code. It evaluates as: 'f' / 1;Re: Perl code that is syntactically correct only on Fridays
#25Re: Perl code that is syntactically correct only on Fridays
#26I had an intern once who wrote similar code. They confused 12 hour and 24 hour clocks, so the code would break after lunch. Unfortunately, the intern only worked the mornings, so it took several days of back and forth before the bug could be finally put to rest.
Re: Perl code that is syntactically correct only on Fridays
#27I had an intern once who wrote similar code. They confused 12 hour and 24 hour clocks, so the code would break after lunch. Unfortunately, the intern only worked the mornings, so it took several days of back and forth before the bug could be finally put to rest.
Re: Perl code that is syntactically correct only on Fridays
#28Earlier quoted context omitted.
Let's be pedantic about this, because this is one of the very few areas where pedantry matters: GMT ("British Winter Time") is NOT UTC, and it can differ from UTC up to 0.9 seconds. GMT is a time zone (corresponding to UT1). UTC is a time standard.
To be pedantic, this is an area where pedantry occasionally matters. For the vast majority of (casual) usage, it doesn't.
Re: Perl code that is syntactically correct only on Fridays
#29Pro tip: add test cases to your CI runs with modified system date.
What date to change to? Far into the future? Far into the past? To a weekend? To a DST change? To Friday the 13th? To a US holiday? To a Muslim, Jewish, Chinese, Soviet, Albanian holiday? To a particular weekday? To Hitler's birthday? What if it's Lenin's? To that one day my coworker was depressed because the boss denied him a raise and talked shit to him? Too many possibilities. And your timebomb might be in one of your dependencies to boot.
Re: Perl code that is syntactically correct only on Fridays
#30Why only things like these float up to the front page, and not elegant and/or wholesome things written in Perl?
And good things in Perl don't get noticed because they Just Work.