in reply to Re: Re: Net::SMTP error
in thread Net::SMTP error

Ummm, perhaps you meant to use 'or' instead of '||' here. '||' has higher precedence than '=', where 'or' has lower precedence than '=', so it is not doing what you think it's doing when you interchange between the two.

In you code you had -
my $smtp = Net::SMTP->new($smtpServer, Timeout => 60) || &do_some_stuf +f $!;
where I assume that &do_some_stuff does some error handling. May be you are not aware, it is actually doing this instead -
my $smtp = (Net::SMTP->new(....) || &do_some_stuff...);
if the object creation fails, your $smtp ends up with whatever is returned from 'do_some_stuff'.

So the more correct way to do error handling here should be -
my $smtp = Net::SMTP->new(....) or &do_some_stuff $!;
where $smtp is assigned to the new object first, and if it is undefined because of failed connection, then the 'do_some_stuff' error handling will kick in.

Replies are listed 'Best First'.
Re: Re: Re: Re: Net::SMTP error
by K_M_McMahon (Hermit) on Dec 13, 2003 at 05:03 UTC
    Hey guys, with some testing I found, what imho might be a better way. You can't use if (!$smtp=Net::SMTP...) in the begining , it won;t accept it, but what does work is just letting the first one go, it won't crash the script if it fails. Then on the next line, test if $smtp is defined. if (!defined($smtp)) if it is defined then opening the server worked, if it is undefined, it failed and you can deal with it from there!!! thanx for your help all!

    -Kevin