in reply to Nested OR as a control structure

or is identical to the operator || except that with ||, function calls need parentheses, while with or they don't.

# this reports a problem if func() fails. func $arg1, $arg2 or warn "error invoking func()"; # so does this func( $arg1, $arg2 ) || warn "error invoking func()"; # Not what you might expect # this invokes func( $arg1, ($arg2 || warn "error invoking func()" ); func $arg1, $arg2 || warn "error invoking func()";

My interpretation is that as the use of paranthese-less function calls became increasingly common, and so did the use of error detection, there was a clash, leading the the invention of or.

But you aren't dealing with expressions, you're dealing with blocks.

You can keep the code in block form, and use if() or unless().

Alternately, you could have the first main and alternate return values which distinguish which one ran. They already need to return true for success and false for failure ... just modify things so dofirstcritical() and dobackupcritical() return different true values. Then you can break the continuation out into a separate block.

# At the top of the file in the configuration section my $first_backup = 1; my $backup_backup = 2; unless ($dontdothis) { my $status = dofistcritical() or dobackupcritical() or die "main and backup failed"; if ( $status == $first_backup ) { dobackupremainder(); } elsif ( $status == $backup_backup ) { dofirstremainder(); } else { die( Invalid status '$status' from first backup component" ); } }

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re^2: Nested OR as a control structure
by tinita (Parson) on Jun 03, 2004 at 11:55 UTC
    or is identical to the operator || except that with ||, function calls need parentheses, while with or they don't.
    there are other differences than that. consider:
    tina@lux:~> perl -wle' @a = qw(a b c); @b = @a or die; @c = @a || die; print "(@b) (@c)"' (a b c) (3)
Re^2: Nested OR as a control structure
by andyf (Pilgrim) on Jun 03, 2004 at 04:25 UTC
    Aye Tom, For a while I suspected || and OR might be synonyms, it seems that || binds more strongly, so I get that 3rd example ok. Using $status to grab the result of whichever one finally ran is nice. I can use that.
    Cheers,
    Andy.