Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

Replies are listed 'Best First'.
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
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);


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://428301]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-21 04:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.