Global symbol requires explicit package name

S

snowdog

Can someone please help me. I've got a perl script I've written to
send notifications to another application. The following lines are in
the same sub under the same package (line#'s included for reference).
The line 255 clearly defined the $action variable. Line 341 tries to
use it in a method for $notificationObj. Perl is telling me that
global symbol $action requires explicit package name on line 341.
Why, it IS defined on line 255.
Funny thing is, I didn't have this problem until I moved the entire
code block under a package main; statement (I'm trying to get this
thing to run as a service).

255: my $action = "notify";
341: my $notificationResult = $notificationObj->invoke($action,
"HowIs_Adapter",
$main::configRef->{'Config.howisServer'},
"HowIs Alarm",
);


I appreciate your help!
 
A

Anno Siegel

snowdog said:
Can someone please help me. I've got a perl script I've written to
send notifications to another application. The following lines are in
the same sub under the same package (line#'s included for reference).

Are they in the same lexical scope?
The line 255 clearly defined the $action variable. Line 341 tries to
use it in a method for $notificationObj. Perl is telling me that
global symbol $action requires explicit package name on line 341.
Why, it IS defined on line 255.

A lot can happen in the intervening 80+ lines.
Funny thing is, I didn't have this problem until I moved the entire
code block under a package main;

If the package statement is relevant, your code should show it.
statement (I'm trying to get this
thing to run as a service).

What does that mean, and how does it require a "package main" statement?
255: my $action = "notify";
341: my $notificationResult = $notificationObj->invoke($action,
"HowIs_Adapter",
$main::configRef->{'Config.howisServer'},
"HowIs Alarm",
);

Your code doesn't demonstrate the error (it would complain about
"$notificationObj"). Prepare a self-contained piece of code that
can be run anywhere and shows your problem. My guess is that in
doing so you will find the error yourself, otherwise post it.

Anno
 
J

Joe Smith

snowdog said:
The line 255 clearly defined the $action variable. Line 341 tries to
use it in a method for $notificationObj. Perl is telling me that
global symbol $action requires explicit package name on line 341.
Why, it IS defined on line 255.

Not necessarily. Here's a short example that shows how something
defined in line 3 becomes undefined by line 5 due to line 4 (and line 2).

use strict; use warnings; # 1
{ # 2
my $action = "notify"; # 3
} # 4
print "\$action is '$action'\n"; # 5

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top