Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: unless....else

by LanceDeeply (Chaplain)
on Aug 06, 2003 at 02:39 UTC ( [id://281250]=note: print w/replies, xml ) Need Help??


in reply to Re: unless....else
in thread unless....else

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?!!!

Replies are listed 'Best First'.
Re: Re: Re: unless....else
by Enlil (Parson) on Aug 06, 2003 at 03:36 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://281250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-20 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found