in reply to Do and Die

#!/usr/bin/perl -w # system ('echo', 'hi 0') or die $@; # INCORRECT WAY TO CHECK FOR F +AILURES my $ret = system ('echo', 'hi 1'); die $@ if $ret; die $@ if system ('echo', 'hi 2'); # Works but i don't think it i +s clean __END__ hi 1 hi 2

Replies are listed 'Best First'.
Re^2: Do and Die
by Transient (Hermit) on Aug 15, 2005 at 19:10 UTC
    To expand - you might want a special case for -1 (unable to start the program)

    my $retval = system( 'cmd' ); if ( $retval == -1 ) { die "Unable to start cmd!\n$!\n"; } elsif ( $? ) { die "Error returned from cmd! (".($?>>8).")\n$@\n"; }