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


In reply to Re: Nested OR as a control structure by TomDLux
in thread Nested OR as a control structure by andyf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.