This Perl error has cost me a few hours of my life and is a nice example of trying to find an answer to a given problem in the internet without ever being successful. This investigation has made me read a lot of things I probably never wanted to know ( e.g. about utf8 encoding in Perl ) until I finally figured out the cause of my problem myself.
This error was caused by a simple syntax error and incorrectly coding access to an element in a hash. May be there is not such a thing like a “simple syntax” error in a powerful language like Perl, since even stupid code can have some meaning.
Anyhow, I was writing something like
1: print OUT $post->("Content");
instead of
1: print OUT $post->{"Content"};
Note the round brackets vs. the curly brackets !
So, if anyone every bumps into the very same strange error because of this syntax fault he or she hopefully finds my blog posting here pretty soon to fix this without wasting too much time.






March 31, 2009 at 8:45 pm
If you find an error message like this again, read perldoc perldiag, or add “use diagnostics;” to your code. That’ll give you more information on what the error means. (In this case, it should give you enough information to solve it.)
April 3, 2009 at 6:59 am
Hi Axel,
Did you try looking in “perldoc perldiag” by any chance? (aka http://perldoc.perl.org/perldiag.html). Thats the doc that lists all the possible warnings perl itself will output.
Jess
April 3, 2009 at 7:19 am
Good hints, folks, thanks chromatic & Jess !
The info I found in perldiag.html is certainly right but in this case not very detailed and probably I still would have not discovered right away what was wrong. But anyway, a good source of information for future perl errors like this.
“use diagnostics” actually delivered more detailed info about the error. Excellent, chromatic, may be the best lesson I learned this week !
April 20, 2009 at 2:40 am
I ran into the same problem today, with the same cause. Didn’t find this until after I’d fixed it.
But now I know, and have some pain to hammer in the lesson, about `perldoc perldiag`.
Fair trade.
April 24, 2009 at 10:29 pm
Thank you! This saved me hours of work! You’re great!
November 8, 2009 at 12:32 am
Just wanted to say thanks. Came across this and had made the same typo in my code. Saved me hours of work.
January 15, 2010 at 9:47 am
Same message but was bizarrely a result of using Apache2::Reload on a mod_perl setup. Yay for randomness!
February 14, 2010 at 7:05 am
Hi, I just had the same error but due to a very different syntax error. To instantiate an object, ObectjPackage->new instead I had ObjectPackage::new->()
In hind site the problem is obvious. I want to live in hind site.
February 24, 2010 at 6:42 am
Got same error due to typo
index($_, ‘UNIX_TIMESTAMP’ == 0)
instead of
index($_, ‘UNIX_TIMESTAMP’) == 0
April 3, 2010 at 9:59 am
Hi all,
I had the same error msg and scratched my head for a while. I added “use diagnostics” after reading this page and the error is gone. I didnt fix anything in my code. I’m really worried that its going to comeback to bite me. So, would like comments in case anyone knows other situations that can lead to this error.
I was getting this error at a completely unrelated line of code compared to where my perl script is executing at that moment. My project involves calling C API from a perl script AND also an embedded perl interpreter in my C library to invoke callbacks defined in the same script. The code from a callback starts executing and Perl throws this error at another completely unrelated part of the code. The same callback code works fine in other locations/scripts.
July 25, 2010 at 9:22 pm
You just save me a few hours, my friend. Many thanks! I ran into this working with MySQL, getting values out from a fetchrow_hashref() call.
January 2, 2011 at 9:37 am
[...] out your blog ?Planing by the hour in MS ProjectPerl Coding Error: do not overwrite your hash !Perl Error “Not a CODE reference …”Alexander [...]
January 7, 2011 at 4:29 am
Another happy customer- thanks for being at the top of the google search for “not a Code reference”!!
January 7, 2011 at 4:37 am
I encountered this problem in a logging routine I was writing. Turns out I didn’t make the same error as above, instead I had the following:
printf $self->{log_fh} (“[%s] %s\n”, $self->timestamp(), $message);
This looks fine but Perl interprets it as accessing &$self->{log_fh}->(parameters); . This could possibly be avoided by wrapping the log_fh in brackets, IIRC.
January 28, 2011 at 6:19 pm
THank you man, you saved me some hours of my life
April 4, 2011 at 3:10 pm
Same error with still a little different cause. Using $q from CGI->new I wrote in one place:
$q->(‘name’) instead of $q->param(‘name’)
Took me about 15 minutes of wondering and debugging to see it…
April 7, 2011 at 8:09 am
“So, if anyone every bumps into the very same strange error because of this syntax fault he or she hopefully finds my blog posting here pretty soon to fix this without wasting too much time.”
I did, cheers bro!
May 5, 2011 at 8:16 pm
I did stumble into your blog after struggling with a syntax error for an hour. I had used () instead of {}. It is so bugging. Your post was helpful
May 6, 2011 at 9:23 am
Thanks for all the comments and nice feedback, folks. One root cause to this problem might be that the curly bracket looks pretty similar to the regular bracket, especially if you have a high resolution monitor and your eyes are not as good anymore as they had been 20 years ago. Thus it becomes simply hard to spot the error.
I am just speaking of myself, of course
February 2, 2012 at 1:20 am
Solved my problem today!! Thanks for sharing.
March 15, 2012 at 7:18 pm
You solved my problem too! I love the internet!
April 9, 2012 at 8:11 pm
another person saved hours of head scratching because, yes, old eyes can sometimes have a hard time telling parens from curly braces. In my case, it was a combination of that and trying to change code from one flavor to another. Thanks…