Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

what is benefit of unless ?

by Anonymous Monk
on Feb 05, 2005 at 11:34 UTC ( [id://428301]=note: print w/replies, xml ) Need Help??


in reply to unless statements

I think unless statements are similar to if statements.But if-else stmt gives us more flexibility then unless.So is there any specific use of this . please reply soon. regards, barun parichha

Replies are listed 'Best First'.
Re: what is benefit of unless ?
by holli (Abbot) on Feb 05, 2005 at 17:43 UTC
    $ cat input foo bar $ perl -ne 'print unless /^$/../^$/' input foo bar $ perl -ne 'print if not /^$/../^$/' input foo bar $ perl -ne 'print if ! /^$/../^$/' input foo bar
    The unless statement is equivalent to if not, but is different from if ! due to the associativity and precedence rules covered in perlop. A benefit of this behavior allows the reduction of runs of blank lines to a single blank line.

    taken from here
Re: what is benefit of unless ?
by Anonymous Monk on Feb 05, 2005 at 12:04 UTC
      is this the equivalent code for " unless(condition)" ? if !(condition) { ... ... } else { ... ... } reply soon, barun parichha
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: what is benefit of unless ?
by prasadbabu (Prior) on Feb 05, 2005 at 12:12 UTC

    It is not similar statement.

    $a = 10; print "if stmt true" if ($a == 10); print "unless" unless ($a == 10);

    Prasad

Log In?
Username:
Password:

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

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

    No recent polls found