Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: if/else syntax

by suaveant (Parson)
on Jun 26, 2009 at 15:07 UTC ( #775084=note: print w/replies, xml ) Need Help??


in reply to if/else syntax

If you want an "else" with an if, you need the brackets, "if" after the statement is a modifier, not a control block... if you just need the else, use unless
print "OK\n" unless $a == 1;

Update: I suppose you could do

print "OK\n" if $a == 1; print "Not OK\n" unless $a == 1;
But don't. ;)

                - Ant
                - Some of my best work - (1 2 3)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2022-10-07 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (29 votes). Check out past polls.

    Notices?