http://www.perlmonks.org?node_id=428301


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