What is Wrong With this Picture?

I’ve just found a number of subroutines defined this way in the code that I’m working on.

I discovered the problem because I started getting errors about “too many parameters”. I knew what the problem was (the empty prototype) but it took a couple of minutes of head-scratching before I realised why it had been working before my changes.

Then I realised.

I have a dislike of “unnecessary” &s on subroutine calls. So almost without realising, I had removed them from the calls to these functions.

A few lessons have been learned.

Lesson 1 (for the original author of this code): Prototypes will trip you up. Do not use them.

Lesson 2 (for me): Ampersands aren’t always as pointless as they appear. They may be masking bugs in the code.

By Dave Cross

Dave Cross runs Magnum Solutions Ltd., a London Perl consultancy. In 1998 he started London Perl Mongers, the first Perl Mongers group outside of Northern America. He is the author of Data Munging with Perl and a co-author of Perl Template Toolkit.

2 comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.