zdog has asked for the wisdom of the Perl Monks concerning the following question:

I have been testing a script that I wrote in the command prompt using ActivePerl and that is where we reach our problem: I keep getting the following error:

Not a CODE reference at ... line 53, <DATA> line 1.

What does this mean? What do I do about it?

The line the error refers to is as follows:

if ($q->('lang') eq '' || $q->('lang') eq $bookinfo[1]) {

I am using CGI.pm .

Thanks.

Zenon Zabinski | zdog | zdog7@hotmail.com

Replies are listed 'Best First'.
Re: What does this mean?
by btrott (Parson) on Jul 18, 2000 at 22:00 UTC
    That should be
    $q->param('lang')
    Probably.

    The syntax you used makes Perl think that $q is a subroutine reference that you're trying to invoke with an argument of lang. $q is not a subroutine (CODE) reference. Hence the error.

      Heh! It is funny how obvious the mistake is, but you still can't put your finger on it, thanks. Where would I be without Perl Monks?

      Zenon Zabinski | zdog | zdog7@hotmail.com

(jcwren) RE: What does this mean?
by jcwren (Prior) on Jul 18, 2000 at 22:07 UTC
    I agree with btrott, and I'll add another little tidbit that caused me to waste a few hours. If you want to change the value in the parameter you're accessing, it's
    $p->param ('lang', "Perl spoken here");
    not
    $p->param ('lang') = "Perl spoken here";
    I beat my head against a wall for over two hours trying to track down why my script wasn't doing what I thought it should be doing. It's there when you read the documentation, but it's easy to overlook, and it's a dumb mistake.

    --Chris

    e-mail jcwren
      I've always preferred the pointy comma operator in this case. It makes it more obvious that you're doing some sort of assignation: $q->param('lang' => 'Perl spoken here');
Re: What does this mean?
by cwest (Friar) on Jul 18, 2000 at 22:09 UTC
    You are trying to use $q as a reference to an anonymous sub. I would expect some code above that line to look something like:
    my $q = sub { my $var = shift; # 'lang' in this case return 1; }
    You would then call the above subroutine using $q as the reference.
    $q->('lang'); # one way &{$q}('lang'); # another way
    Also, you can find out what kind of a reference $q is with the following (after $q is defined and assigned)
    print ref($q);
    I don't know what this has to do with CGI.pm unless you assigned $q as a CGI class reference, and you're using it wrong, or re-assigned it or something...

    Perhaps you just forgot to put the sub's name in your statement... for instance:

    $q->h1('lang'); # instead of $q->('lang')
    --
    Casey
    
Re: What does this mean?
by ferrency (Deacon) on Jul 18, 2000 at 22:04 UTC
    It would be much easier to fix your problem with a larger code snippet.

    Not a CODE reference at ... line 53, <DATA> line 1. if ($q->('lang') eq '' || $q->('lang') eq $bookinfo[1]) {
    This looks like you're dereferencing $q and calling it as a subroutine call. What does $q contain? If it's a hash reference, then to get the 'lang' key out, you should do this instead:

    $q->{'lang'}
    Note the curly braces, instead of parentheses.

    Alan

      Oops- nevermind... I missed the part about "CGI.pm".