[wellylug] Perl Help
Grant McLean
grant at mclean.net.nz
Mon Sep 13 13:24:20 NZST 2004
On Mon, 2004-09-13 at 12:23, Chris Hodgetts wrote:
> I added the or die "$!"; and it is now working...
>
> can you explain please?
I wish I could :-)
The reason I suggested adding that to the end is because it
would cause the script to stop at the point of the failure
rather than at some later point as a side effect of the
failure. The $! special variable expands to the last error.
Adding 'or die ...' should not cause it to start working.
Are you sure you didn't change anything else?
More notes below...
> On Mon, 2004-09-13 at 12:16, Chris Hodgetts wrote:
> > This may give more indication
> >
> > if ($passed <1)
> > {
> >
> > my
> > $smtp=Net::SMTP->new('127.0.0.1',(Hello='thismachine.thatdomain.foo.nz'));
This looks wrong. The Hello should be followed by => rather
than =. There is also no need for the extra parentheses.
my $relay = '127.0.0.1';
my $smtp = Net::SMTP->new($relay, Hello =>
'thismachine.thatdomain.foo.nz') or die "$relay: $!";
I'd omit the Hello bit altogether unless your SMTP server demands it:
my $relay = '127.0.0.1';
my $smtp = Net::SMTP->new($relay) or die "$relay: $!";
> > $smtp->mail("firstname.lastname\@somedomain.foo.nz");
This is also missing error handling. I would be inclined to write
it as:
$smtp->mail("firstname.lastname\@somedomain.foo.nz")
or die "\$smtp->mail(): " . $smtp->message();
Same goes for all the following message calls.
> > $smtp->to("firstname.lastname\@somedomain.foo.nz");
> > $smtp->data();
> > $smtp->datasend("To: firstname.lastname\@somedomain.foo.nz\n");
> > $smtp->datasend("Date: $thisday, $thisdate $thismonth $thisyear
> > $hour:$min\n");
> > $smtp->datasend("Subject: Server5 Error Report $timestamp\n\n");
> > $smtp->datasend("Error Report:\n$errorDescription");
> > $smtp->dataend();
> > $smtp->quit();
> >
> >
> > The guy who wrote this script has since left the company, and before he
> > left we migrated it over to another box, and it has never worked, and he
> > didnt care...
> >
> > On Mon, 2004-09-13 at 11:11, Grant McLean wrote:
> > > On Mon, 2004-09-13 at 10:44, Chris Hodgetts wrote:
> > > > Hello,
> > > >
> > > > I am trying to use perl mail modules, and I think I have installed the
> > > > correct ones, but clearly not, because I am getting the following error:
> > > >
> > > > Can't call method "mail" on an undefined value at
> > > > /home/test/serv5/testS5.pl line 59.
> > > >
> > > > Debian Unstable is the distro I am using, can anyone let me know what
> > > > packages "Should" be installed for this to work?
> > >
> > > Hmm, that message doesn't give us much to go on and it certainly
> > > doesn't imply that the cause is a missing package.
> > >
> > > Presumably line 59 of the script has something like this:
> > >
> > > $some_var->mail('some arguments');
> > >
> > > The error message is telling us that the variable ($some_var in the
> > > example above) is empty when the script expects it to contain an
> > > object of some sort. This in turn implies that an earlier line in
> > > the script attempted to create an object, perhaps like this:
> > >
> > > $some_var = Net::SMTP->new('stmp.some.domain');
> > >
> > > And that line is failing for some reason. A better way to write that
> > > line would have been:
> > >
> > > $some_var = Net::SMTP->new('stmp.some.domain') or die "$!";
> > >
> > > That way you'd get an error indication at the time of the actual
> > > failure rather than later on.
> > >
> > > My examples assume the Net::SMTP module was being used. This is part
> > > of the core Perl distribution. In your case, it could well be a
> > > completely different module - typically included near the start of
> > > the script with a line like this:
> > >
> > > use Net::SMTP;
> > >
> > > Cheers
> > > Grant
> > >
> > >
> >
>
More information about the wellylug
mailing list