die question

Discussion in 'Perl' started by daniel kaplan, Sep 14, 2004.

  1. 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
     
    daniel kaplan, Sep 14, 2004
    #1
    1. Advertising

  2. Gunnar Hjalmarsson, Sep 14, 2004
    #2
    1. Advertising

  3. 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
     
    Sherm Pendley, Sep 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Nilsson

    Assign program result or die

    Martin Nilsson, Jul 15, 2004, in forum: Perl
    Replies:
    1
    Views:
    523
    J├╝rgen Exner
    Jul 15, 2004
  2. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    446
    Natty Gur
    Jan 26, 2004
  3. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    460
    Alvin Bruney
    Jan 25, 2004
  4. Ted
    Replies:
    1
    Views:
    599
    Eric Lawrence [MSFT]
    Mar 1, 2004
  5. die
    Replies:
    2
    Views:
    80
    Gunnar Hjalmarsson
    Dec 22, 2004
Loading...

Share This Page