Live data from Hacker News

Perl code that is syntactically correct only on Fridays

github.com

201–210 of 233 posts

Re: Perl code that is syntactically correct only on Fridays

#201

Earlier quoted context omitted.

Because with its declining popularity, most people here are unfamiliar with the language except for its meme status as "that weird line noise language". Things that confirm pre-existing beliefs are easy to accept and upvote, whereas good Perl code would require (a) some actual thinking, and (b) challenging the socially accepted narrative - both of which are relatively much harder.

Good Perl code would also look pretty boring, almost like enterprise Java. I'd wager that all code that "just works", in any language, looks bland and predictable. But I'd rather have that than cute and clever any day.

You say that but a lot of people just can't get over the sigils.

Re: Perl code that is syntactically correct only on Fridays

#203

I 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?

The line

    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)

Re: Perl code that is syntactically correct only on Fridays

#204

Why only things like these float up to the front page, and not elegant and/or wholesome things written in Perl?

The other day, I wanted to check if a text file's 100,000th word was being indexed, so I generated a text file with 99,999 lines containing "foo" and one line with "bar" with this line in bash

perl -e 'print "foo\n" for 1..99999; print "bar\n";' > foobar.txt

Re: Perl code that is syntactically correct only on Fridays

#205
post #10

I 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.

We had situation where if you worked late, the test suite would consistently fail. Since developers rarely worked late and would give up when hitting the "random" test suite failure and go home, the bug persisted for months before the true cause was understood. Our time zone was UTC-5, and the test suite contained a local-vs-UTC bug which only triggered between 7pm and midnight.

I had to fix tests that broke from 11pm-midnight because some assumptions that now() + 1 hour was the same local date.

Re: Perl code that is syntactically correct only on Fridays

#206

Earlier quoted context omitted.

Thank you for this. I hate trying to read Perl so much. What is the "#/+" for?

Worked as a Perl dev for 15 years and enjoyed it. The hardest thing was the number of ways to do OO Perl using Perl5. Everyone has their own flavor. And TMTOWTDI was a motto the community was proud of. Having said that, nothing could touch mod_perl performance under Apache in the late 90s. Massive web apps were built on this including eToys dot com where I worked before it imploded in the dot-com bust.

Moose, Mouse, Moo, Mo ... bah! Just give me The Damian's simple blessed hashref.

Re: Perl code that is syntactically correct only on Fridays

#207

Earlier quoted context omitted.

Worked as a Perl dev for 15 years and enjoyed it. The hardest thing was the number of ways to do OO Perl using Perl5. Everyone has their own flavor. And TMTOWTDI was a motto the community was proud of. Having said that, nothing could touch mod_perl performance under Apache in the late 90s. Massive web apps were built on this including eToys dot com where I worked before it imploded in the dot-com bust.

> Worked as a Perl dev for 15 years and enjoyed it Similar situation here. Perl is awsome and I'm still bitter that Python won. I mean significant whitespace - what great madness is this??? Anyway, yes, mod_perl ran the Web for about a decade in the early 2000s and I built and maintained huge websites which were all Perl on the back end. BTW the book "Perl Best Practices" by Damian Conway [0] is the best general prog…

The Damian was a phenomenon of pure inspiration. In fact Perl community in general had a pantheon of acolytes I've never seen in any other programming community. Ruby has a few but nowhere near as many as Perl. Perl in the early 2000s really was on fire.

Re: Perl code that is syntactically correct only on Fridays

#208
post #200

Earlier quoted context omitted.

Worked as a Perl dev for 15 years and enjoyed it. The hardest thing was the number of ways to do OO Perl using Perl5. Everyone has their own flavor. And TMTOWTDI was a motto the community was proud of. Having said that, nothing could touch mod_perl performance under Apache in the late 90s. Massive web apps were built on this including eToys dot com where I worked before it imploded in the dot-com bust.

Perl makes you think differently. True for all languages I guess, but maybe a little truer for Perl than most. I've moved on but still use it for simple scripting tasks despite doing my best to learn Python. I just feel so expressive and unconstrained writing it, for better or worse.

Ruby is a much better option than Python for expat Perl geeks.
Post reply on HN