Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   die question (http://www.velocityreviews.com/forums/t25365-die-question.html)

daniel kaplan 09-14-2004 10:27 PM

die question
 
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



Gunnar Hjalmarsson 09-14-2004 10:43 PM

Re: die question
 
daniel kaplan wrote:
> i want to turn this line
>
> ...


See reply in comp.lang.perl.misc. This group is defunct.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Sherm Pendley 09-14-2004 10:54 PM

Re: die question
 
daniel kaplan wrote:

> 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--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


All times are GMT. The time now is 11:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.