I’ve just found a number of subroutines defined this way in the code that I’m working on.
1 2 3 4 |
sub do_something () { my $parameter = shift; ... } |
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.
Funny. I didn’t know that “&” can bypass prototypes.
Neither, apparently, did the person who originally wrote that code π