[lug] Perl question
Zan Lynx
zlynx at acm.org
Mon Apr 6 18:04:17 MDT 2009
Carl Wagner wrote:
> Hi,
>
> I am working on a Perl module that someone else wrote.
>
> I moved a sub from one file to another. The sub contained a switch
> statement.
> I included "use Switch" near the top of the module.
>
> The Perl program would fail with the error:
> # cat server.log
> Number found where operator expected at Module1.pm line 823, near "case 2"
> (Do you need to predeclare case?)
> Number found where operator expected at Module1.pm line 824, near "case 3"
> (Do you need to predeclare case?)
> Did not find leading dereferencer, detected at offset 41073syntax error
> at Module1.pm line 822, near ")
> {"
> syntax error at Module1.pm line 824, near "case 3"
>
>
> But if I include "use Switch" within the sub, it works fine.
>
> Any idea why I can't just do a "use Switch" at the top of the module?
> (I have "use Strict" near the top).
>
Any "use" statements must be inside the scope of the "package" that
wants to use them. What is probably happening is something like this:
use Switch;
.
.
.
package Blah;
switch
What you need is:
.
.
.
package Blah;
use Switch;
switch
--
Zan Lynx
zlynx at acm.org
"Knowledge is Power. Power Corrupts. Study Hard. Be Evil."
More information about the LUG
mailing list