in reply to Subroutine Reference with use strict

You can't give prototypes to sub references like that. Drop the (@), and drop the quotes. Don't worry about the prototypes as sub references are always called at run-time, and protypes aren't even checked at run time. Besides, no prototype equals (@).

%states = ( Default => \&front_page, Lost => \&lost, );
By the way, there is no Apache::Register (at least not in my CPAN mirrors). It's called Apache::Registry.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Subroutine Reference with use strict
by chiller (Scribe) on Apr 13, 2002 at 20:41 UTC
    I gave the prototype to the subroutine reference because without it, I get the "Prototype Mismatch" error, IN ADDITION TO the subroutine error.

    There is not a (@) prototype?! Programming Perl 3rd ed. lists them on pg. 226. :)

    Yes, it's Apache::Registry, sorry.

      The prototype problem is probably because you didn't have just \&foo, rather something like \&foo(), in which case the subroutine foo would have been run, which would result in prototype mismatch. However, if you leave out the parentheses completely no subroutine call will be made and such no prototype check will occure there. If you do like Juerd and rinceWind said then you're home safe. You must realize that & is the sigil of subroutines, just like $ is the sigil of scalars. So you use & to address it, not call it. If you want to execute the subroutine then you use parentheses, but not otherwise.

      (Disclaimer to other monks: Yes, I know this is very simplified and I know about &foo and it's magical @_ treatment, but that's another issue and let's not confuse he who seeks help with almost irrelevant details.)