Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

With what I have here:
if(($sym == 1) && ($mac == 1)) { print STDERR "Both not avail\n"; exit 0; }
Can I do this?
print STDERR "Both not avail\n";exit if(($sym == 1) && ($mac == 1));
Is there a better way or is this the best way to do this? I am puzzled if I can put the "exit" in the above statement the way I have it?

Replies are listed 'Best First'.
•Re: Condense the script
by merlyn (Sage) on Oct 07, 2003 at 17:39 UTC
Re: Condense the script
by thelenm (Vicar) on Oct 07, 2003 at 17:42 UTC

    You can do this by saying:

    print STDERR "Both not avail\n" and exit if (($sym == 1) && ($mac == 1 +));

    but it may be even easier just to die, like so:

    die "Both not avail\n" if (($sym == 1) && ($mac == 1));

    -- Mike

    --
    XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
    -- grantm, perldoc XML::Simpler

      thanks
print as method call
by ambrus (Abbot) on Oct 08, 2003 at 11:34 UTC
    You can do this: use IO::Handle; STDERR->print("not avail\n"), exit if $sym==1 && $mac==1;.

    Or even (ugly!): exit not print STDERR, "not avail" if $sym==1 && $mac==1;

    or syswrite(STDERR,"not avail\n"), exit 0 if $sym==1 && $mac==1;

Re: Condense the script
by perl_in_NH (Initiate) on Oct 07, 2003 at 18:24 UTC
    die "Both not avail\n" if $sym+$mac==2;

      What happens if $sym == 2 and $mac == 0 ?

        you get a nasty bug that takes a long time to track down and a maintainer of your poor script that wants to track you down and $knife++ you.


        -Waswas