in reply to Re: Re: Re: Re: Global symbol requires explicit package name
in thread Global symbol requires explicit package name

Eeek! Thanks, chromatic. As penance for my sin, I shall recite the appropriate scripture, from perldiag:
       Can't call method "%s" without a package or object reference
           (F) You used the syntax of a method call, but the slot
           filled by the object reference or package name con­
           tains an expression that returns a defined value which
           is neither an object reference nor a package name.
           Something like this will reproduce the error:

               $BADREF = 42;
               process $BADREF 1,2,3;
               $BADREF->process(1,2,3);
Well, I guess that leaves me a bit cold, though -- the example is a bit contrived and its relation to the case at hand is far from obvious. Nickd_69's OP (and his various replies) should give enough info to figure out how this diagnostic applies to his particular case.

Could anyone enlighten us as to what this really means (and why one of the alternatives that I (cough) guessed at (ahem) seemed to solve the problem)? Thanks.

  • Comment on Re: Re: Re: Re: Re: Global symbol requires explicit package name

Replies are listed 'Best First'.
Re6: Global symbol requires explicit package name
by rinceWind (Monsignor) on Aug 15, 2003 at 11:26 UTC
    $mailer->close is method call syntax. Perl knows that it needs to generate a subroutine call, passing an object as the first implicit parameter.

    What happens if $mailer is undef or some other scalar value, which is not a blessed object reference?

    Well, this generates a run time error of the form Can't call method "close" without a package or object reference

    If $mailer happens to be a string containing a package name, then the method call will work, passing in the package name as first implicit parameter. For example, the new method as in:

    my $pkg = "Foo::Bar"; my $obj = $pkg->new;
    Note that an ordinary class method call uses this form, but with a bareword package name (which is made into a string).

    Hope this helps

    rinceWind