Global symbol requires explicit package name

Discussion in 'Perl Misc' started by snowdog, Nov 5, 2004.

  1. snowdog

    snowdog Guest

    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!
     
    snowdog, Nov 5, 2004
    #1
    1. Advertising

  2. snowdog

    Anno Siegel Guest

    snowdog <> wrote in comp.lang.perl.misc:
    > 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
     
    Anno Siegel, Nov 5, 2004
    #2
    1. Advertising

  3. snowdog

    Joe Smith Guest

    snowdog wrote:

    > 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
     
    Joe Smith, Nov 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xxx
    Replies:
    0
    Views:
    855
  2. sam

    requires explicit package name

    sam, Jan 6, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    249
    Tad McClellan
    Jan 12, 2005
  3. Replies:
    5
    Views:
    1,095
    Sherm Pendley
    Jan 28, 2005
  4. mike
    Replies:
    3
    Views:
    690
    Dr.Ruud
    Apr 30, 2008
  5. Replies:
    6
    Views:
    1,878
Loading...

Share This Page