Blog entries tagged with "programming"

When should you use the backtick operator?

Tuesday, May 8th, 2007 at 07:17pm

In Perl, PHP and shell (maybe others as well) the “`” character (informally known as the backtick and formally known as a Grave accent) is used to execute a shell command and return the output as a string.

Perl and PHP have other methods of achieving the same result that are not elements of syntactic sugar. These are less likely to surprise you, as I found today when I noticed that the computer collection section of this site was breaking in a strange way.

For those pages I use PHP to build up the page based on the directory structure and the existence of certain files. The first thing I checked was that the files were actually present. They were.

The next thing to check was the error log and here I found a number of messages telling me that shell executions were disabled. That made sense in relation to a recent change in the security configuration that the hosting people had made, but what was I executing on the shell?

As the error message was nice enough to tell me the specific file and line number I quickly found this call:


This is running pwd in a shell to get the current directory and then using trim() to remove excess whitespace. This is stupid. Especially since the following does exactly the same thing:


This has a crucial difference; it is built into the language, no shell execution (and potential security hole) is required.

To answer the original question: Use backticks to execute a shell command only if, for some bizarre reason, there is nothing built into the language or a module cannot be loaded to achieve the same result.

Tagged with: ,

Hackers and Painters

Saturday, December 4th, 2004 at 08:59am

Last night I finished reading the book that I started earlier in the week, Hackers and Painters by Paul Graham, and I’m realising it was probably a bad idea. Not that I’m saying there is anything wrong with the book… just that I have an information overload right now due to OSDC

Currently I am excellent at perl (what I do at work and mostly at home), passable at PHP (what this site and others is in) and for some time I have been comtemplating learning another language. This book has insipred me to choose Lisp and the LISP Primer looks like a good starting point.

Unfortunately the OSDC has inspired me to learn the basics of python which the Python Tutorial should give me. Naturally both of these languages will be added to my todo list alongside Java (because unfortunately if something happened to my position at Monash…) which means that I may never get around to any of them…

Tagged with: ,

Wiki’s are also good

Tuesday, October 7th, 2003 at 11:22pm

At work today I was moving the style guide into the wiki which led me over to the original WikiWikiWeb to see if I could do an InterWiki link for Rob Pike (I included some quotes he made about software engineering in the style guide).

Anyway the point I am getting to is that it reminded me that I had been meaning to have a look at The Practice of Programming and it was interesting to see that a lot of other people share the view that all these ‘new’ software development techniques – ie Expert, Agile, Aspect, etc – are basically just a rewording of the practices that have been followed for some time.

I have also added Informal History Of Programming Ideas to my list of things to read…

Some other books that have been recommended to me are: * Peopleware * Code Complete

Tagged with: ,