[cgiapp] re: why do I get "Bad name after ::" in Perl?
Richard Jones
ra.jones at dpw.clara.co.uk
Thu Sep 25 15:57:41 EDT 2008
Mark Stosberg wrote:
>> [Dispatch] ERROR' for request '/': Unable to load module
>> 'WebApp::Controller::Foo': Bad name after :: at
>> WebApp/Controller/Base.pm line 98.
[..]
> You need quotes around the package name. With them 'WebApp::DB::' is
> like a constant...and you just can't concatenate variables like this.
>
> This little script demonstates the bug and the fix:
>
> package Foo::Zoo;
> sub new { print "you found me!\n"; }
>
> package main;
> use strict;
>
> my $a = 'Zoo';
>
> # Uncomment either one for testing.
> Foo::$a->new;
> # "Foo::$a"->new;
>
Yes, thanks Mark. Strangely enough I did something similar myself with a
demo script and switched diagnostics on (something I had forgotten
existed), and found the explanation about the quotation marks. But your
demo app was much more elegant than mine :)
More information about the cgiapp
mailing list