in reply to unless....else

You can even have:
unless (...) { ... } elsif (...) { ... } else { ... }

Abigail, who isn't surprised by something that's clearly documented.

Replies are listed 'Best First'.
Re: Re: unless....else
by LanceDeeply (Chaplain) on Aug 06, 2003 at 02:39 UTC
    Update: Please delete/ignore this. It's much too late for me to be typing anything remotely resembling code.

    use strict; use warnings; unless( 1 ) { print "Hello\n"; } unless( 2 ) { print "World\n"; } else { print "WHAT?!!!\n"; } __END__ WHAT?!!!
      Unless I am mistaken you are trying to show that unless the first condition is false or that the second considition is false, then print the stuff in the else statement(kind of akin to an if/elsif/else construct, but for unless). At least that is the jist of what I got from your post (forgive me if I am wrong, but want to make sure that no one is led astray here).

      Anyhow the reason WHAT?!!! is printed is not because neither of the unless conditions were false (and hence executed), but because the second statement's condition (i.e. unless( 2 ){ .. } ), was true (and not executed), and thus the else that follows is executed. For example:

      will print both "TEST 1" and "TEST 3"

      -enlil

        LanceDeeply should have been surfing porn rather than posting code