Learning Perl through code golf

Before I started with my current employer almost six years ago I moved from a small, privately-owned, web development company with a few developers working in the languages we chose (or at least, could make a good enough argument for) and with tools recommended by each other or the latest and greatest libraries we’d recently discovered. This was great fun and whilst we dabbled in other languages, learning Ruby and Python, tinkering with shell scripts and Haskell, there were things we didn’t touch because we didn’t have to. That was, until another developer that was no longer with us, created a Perl script that needed updating. The fear in our eyes when that script came up, or when it needed to be used again for another client…

Continue reading “Learning Perl through code golf”

String Variable Concatenation

I stumbled across something odd today in PHP:

Now, personally, I’d have expected a syntax error from the above code, but the result was even more confusing at first…

Not sure if this was the expected output or not I tested similar code in other languages:





That explains it!

So the reason the string is ‘aaaa’ seems to be that the code is evaluated from right to left:

I don’t think it’s a bug, well, at least I assume not, but is there a name for this?

Update: I asked some clever people for help understanding it.