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

You are a perl god. Of all the people you have been most helpful by far. Have got this error now but I don't think it would be too hard to solve. It is: Can't call method "close" without a package or object reference at enquiry02.pl line 36. It is referring to the line: $mailer->close; Any ideas?? What could be wrong with the line??
  • Comment on Re: Re: Global symbol requires explicit package name

Replies are listed 'Best First'.
Re: Re: Re: Global symbol requires explicit package name
by graff (Chancellor) on Aug 15, 2003 at 02:40 UTC
    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.

      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.

      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!).