Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Strict error on var when using Mail::SendMail

by davidov0009 (Scribe)
on Mar 22, 2007 at 04:16 UTC ( [id://605954]=perlquestion: print w/replies, xml ) Need Help??

davidov0009 has asked for the wisdom of the Perl Monks concerning the following question:

This should be a relatively simple problem to fix for those of you with more wisdom. It comes from using strict. I am calling upon 2 variables created when a function is run from an module. The script is as follows:
use strict; use diagnostics; use Mail::SendMail; my %mail=( To => 'xxxxxxx@xxxxxx.com', From => 'yyyyyyy@hyyyyy.edu', Message => "Message Body" ); sendmail(%mail) or die $Mail::SendMail::error; print "Log Message:\n", $Mail::SendMail::log;
The error states that I have only used $Mail::SendMail::error and $Mail::SendMail::log once during
the script and relates this to a possible typo,
("Mail::SendMail::error" used only once: possible typo ....)
when all I want to do is call the variables once, since, supposedly they have been defined since
the call to the sendmail() function. How can I fix this error?

Replies are listed 'Best First'.
Re: Strict error on var when using Mail::SendMail
by ikegami (Patriarch) on Mar 22, 2007 at 04:26 UTC

    To disable the warning for those two variable:

    # Prevent "used only once" warning for these variables. $Mail::SendMail::error = $Mail::SendMail::error; $Mail::SendMail::log = $Mail::SendMail::log;

    To disable the warning for all variables:

    no warnings 'once';

    Update: There actually is a typo! $Mail::SendMail::... should be $Mail::Sendmail::....

Re: Strict error on var when using Mail::SendMail
by rhesa (Vicar) on Mar 22, 2007 at 04:27 UTC
    It's not actually an error, and it's not strict that's complaining. It is in fact a warning, and diagnostics warns you.

    I don't think the diagnostics pragma allows you to selectively disable its messages, like you can with e.g.  no warnings 'once', but you can turn all diagnostics off and on:

    use diagnostics; disable diagnostics; do_naughty_stuff(); enable diagnostics; do_nice_things();
    For more details, see the manuals for diagnostics and warnings.

      That doesn't work for two reasons.

      • disable diagnostics; only affects run-time warnings. "used only once" is a compile-time warning.
      • disable diagnostics; doesn't disable the warning, just the diagnostic. So while disable diagnostics; would remove the diagnostic message, the basic warning message would still be displayed.

      The solution is to eliminate the warning (using no warnings 'once'; for example), since there's no diagnostic message if there's no warning.

Re: Strict error on var when using Mail::SendMail
by arc_of_descent (Hermit) on Mar 22, 2007 at 11:59 UTC

    You can try this out:

    use strict; use warnings; use Mail::Sendmail qw/ sendmail $error $log /; my %mail=( To => 'xxxxxxx@xxxxxx.com', From => 'yyyyyyy@hyyyyy.edu', Message => "Message Body" ); sendmail(%mail) or die $error; print "Log Message:\n", $log;

    --
    Rohan

Re: Strict error on var when using Mail::SendMail
by Herkum (Parson) on Mar 22, 2007 at 14:11 UTC

    Better to do use warnings than use diagnostics. Diagnostics tends to be pretty dumb and the error messages are overly verbose and are harder to control.

    Your code is a good example of this.

Re: Strict error on var when using Mail::SendMail
by 13warrior (Acolyte) on Mar 22, 2007 at 18:53 UTC
    I think the message yo are getting is due to the enabling diagnostics. I feel use warnings is better than use diagnostics as it diagostics is just the verbose part of it.
      Thanks your comments have helped me solve the problem, and I no longer will use diagnostics, but instead, warnings.

      Now I have one error left, it is an "undefined subroutine &main::sendmail"

      This function should have been exported to the namespace by default upon my call to the Mail::SendMail module, as the CPAN documentation states: sendmail is the only thing exported to your namespace by default.

      I have tried calling it with a & in front, and also placing the Mail::SendMail::sendmail namespace in front, nothing seems to work.

      Any ideas why it seems I cannot call the subroutine?

        I should have pointed this out in my earlier post. Isn't Mail::SendMail a typo? It should be Mail::Sendmail. Hope this helps.


        --
        Rohan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://605954]
Approved by ikegami
Front-paged by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found