Earlier quoted context omitted.
It is formally proven that Perl can't be parsed! https://www.perlmonks.org/index.pl?node_id=663393
It can be externally parsed with ambiguities. The article is written by someone who authored such a parsing toolkit about three years later. Despite what you may have learnt, an ambiguous parse tree is still a useful thing to have, we can build tools taking it into account, also most existing tools can be modified in a straightforward fashion to make use of the extra nodes. The real Perl parser disambiguates with heu…
Perl code that is syntactically correct only on Fridays
101–110 of 233 posts
Re: Perl code that is syntactically correct only on Fridays
#102Earlier quoted context omitted.
To be pedantic, this is an area where pedantry occasionally matters. For the vast majority of (casual) usage, it doesn't.
Indeed. I get invites from people from the UK who simply refer to the current local time (GMT or BST) as "GMT". It just means current London time to them.
Re: Perl code that is syntactically correct only on Fridays
#103Earlier quoted context omitted.
> an intern who wrote code .... his code had been in production You get what you pay for, eh?
A cronjob to sync the time instead of a proper NTP client doesn't sound that good either. I know that each place has its own weird things because historical reasons but NTP is quite ancient.
Re: Perl code that is syntactically correct only on Fridays
#104I 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.
I once had to implement date picker that returned the date to be sent to backend to fetch the day's reservations. It seemed to work fine the day I implemented it. Next day it broke. Turned out the widget returned MM/DD/YYYY instead of DD/MM/YYYY. And I implemented it on 10th of October.
Re: Perl code that is syntactically correct only on Fridays
#105Earlier quoted context omitted.
Personally I really don't like code that deals with time - it's too easy to place a "get time stamp" call anywhere in code. If it's down in the bowels of some piece of functionality trying to test it becomes a headache.
This is one of those pieces of software engineering wisdom that only comes from experience. Try explaining to a newish dev why they shouldn't `const now = Date.now()` or whatever anywhere they want, but rather do it in one place for the lifecycle and pass it around, and they will look at you funny and think it's a waste of time. Classic case of simple vs easy. Time has the potential to complect everything it touches.
Re: Perl code that is syntactically correct only on Fridays
#106I don't get it! It is clearly written in the code, that the progam should behave this way. 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?
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.
Re: Perl code that is syntactically correct only on Fridays
#107This is how it works: BEGIN { # an execution block that runs when the module is compiled *f = # assigns to the symbol "f" inside the symbol table ... (localtime->wdayname eq 'Fri') # is it Friday? ? sub() {} # ... on friday an anonymous subroutine taking no arguments : sub {}; # ... on every other day a subrouting taking arguments } # closes the execution block # The following line executes the subroutine "f" and div…
If you add a 1 to the end of the "f/1;#/+" line, so that it becomes "f/1;#/+1", the code will become correct.
What's actually happening is that on Fridays, the "f/1;#/+" line means "call f, divide the result by 1, and throw away the result", followed by a comment. On any other day, it means "call f with the regex parameter /1;#/ and add an unspecified parameter to it". Since the right hand side of the + operator isn't specified, it is syntactically incorrect.
Re: Perl code that is syntactically correct only on Fridays
#108This is how it works: BEGIN { # an execution block that runs when the module is compiled *f = # assigns to the symbol "f" inside the symbol table ... (localtime->wdayname eq 'Fri') # is it Friday? ? sub() {} # ... on friday an anonymous subroutine taking no arguments : sub {}; # ... on every other day a subrouting taking arguments } # closes the execution block # The following line executes the subroutine "f" and div…
> # The following line executes the subroutine "f" and divides the result by 1 on fridays > # but on other days causes the interpreter to trigger a syntax error You have this the opposite way round to what's happening (and the description). It only compiles on a Friday, i.e. when the sub takes no arguments. Removing all the "only on a Friday" stuff boils down to the difference between these two: # this compiles sub f…
Isn't that what the parent said, going by your quote? They said "the following line [...] on fridays but on other days causes the interpreter to trigger a syntax error".
Re: Perl code that is syntactically correct only on Fridays
#109Earlier quoted context omitted.
Right, the beauty of this is that it's a syntax error he's produced. Sure any language can write code to produce a runtime error under any condition at all. And a lot of languages have features that allow them to run code at compile time, and similarly produce errors then too. But those languages don't allow you to ruin the syntax of the language. I guess it's something that requires macros. Would it be safe to say t…
Bash parses as it runs so something as simple as this works if [ $(date +%u) -ne 5 ] then exit fi (
But that's not bulletproof; consider this code (adapted from https://hal.archives-ouvertes.fr/hal-01513750/document>):
if [ $(date +%u) -eq 5 ]
then
alias maybe=''
else
alias maybe=:
fi
maybe for x in; do :; done
"sh -n" always reports syntax error, even thought the script syntax is correct on Fridays.Re: Perl code that is syntactically correct only on Fridays
#110Yes, apparently.