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

I haven't used the Mail::Mailer module myself. Since you have it installed, you should be able to do "perldoc Mail::Mailer" to read about it (or lookup the man page at www.cpan.org).

My initial guess would be that its "close" function is not "exported" to your script by default (though this would seem uncooperative); have you tried:

use Mail::Mailer (qw/close/);

update: having just looked at the docs on CPAN for Mail::Mailer, it may be that the correct means is:

use Mail::Mailer qw(mail);
Though why this should make a difference is beyond me. (This module is not exemplary in its documentation.) Anyway, you could also try just removing the "close" statement -- when the script exits, the mail object is bound to close.

Replies are listed 'Best First'.
Re: Re: Re: Re: Global symbol requires explicit package name
by chromatic (Archbishop) on Aug 15, 2003 at 03:00 UTC

    This is incorrect. Method calls do not need to be exported. That's the point!

    Besides that, that's never what the error message means.

    If you don't know an answer, please don't guess! Instead, look up the error message in perldiag and educate yourself before you lead people astray.

      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.

        $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

Re: Re: Re: Re: Global symbol requires explicit package name
by Nickd_69 (Novice) on Aug 15, 2003 at 02:59 UTC
    The second line you just added gave me the same error but the first one worked. The only problem is the my web server doesn't have close.pm on it to close the mailer so I am trying to get them to put it on now. Pretty weird how the first one worked and the second didn't. At least the script finally works. (Well I hope!).