die question

D

daniel kaplan

i want to turn this line

open MAIL, "| /usr/sbin/sendmail -t" || die "Could not open sendmail: $!";


into something that goes like

some variable = open MAIL, "| /usr/sbin/sendmail -t";
if (!some variable)

how do i? am too new at perl
 
S

Sherm Pendley

daniel said:
i want to turn this line

open MAIL, "| /usr/sbin/sendmail -t" || die "Could not open sendmail: $!";


into something that goes like

some variable = open MAIL, "| /usr/sbin/sendmail -t";
if (!some variable)

how do i? am too new at perl

What have you tried? As documented, open() returns undef on failure and
a non-zero value on success, so it should work just about how you've
written it:

my $some_variable = open MAIL, '| /usr/sbin/sendmail -t';
if (!$some_variable) {
...
}

That's if you *really* want to store the result of the open() for later.
If all you want is to execute a block of code when it fails, instead of
just a die(), you could do this:

unless (open MAIL, '| /usr/sbin/sendmail -t') {
...
}

By the way, you shouldn't be piping directly to sendmail - there are
CPAN modules that are simpler, and don't rely on the presence of a
specific mailer.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top