Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

what is benefit of unless ?

by Anonymous Monk
on Feb 05, 2005 at 11:34 UTC ( #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


Comment on what is benefit of unless ?
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
      You can use the if/else statement intead of "unless" but it requires more commands of if/else than "unless" and the loop continues as long we required
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

Re: what is benefit of unless ?
by holli (Monsignor) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-09-17 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (57 votes), past polls