in reply to Re: Simplify code in Perl with "unless" loop
in thread Simplify code in Perl with "unless" condition

Oh yes ! I did a big mistake. INdeed, it's a conditionnal and not a loop..end of week Thanks , i changed it in my post edit
Lost in translation
  • Comment on Re^2: Simplify code in Perl with "unless" loop

Replies are listed 'Best First'.
Re^3: Simplify code in Perl with "unless" loop
by Marshall (Canon) on May 27, 2016 at 15:59 UTC
    When you update your post: use strike tags and then put in correction. If you change the question mid-stream, posts to the original question are confusing. Make this update explicit.

    And yes "unless" is just the "NOT of if". These are all the "same".

    #!/usr/bin/perl use strict; use warnings; my $x = 5; print "x not 3\n" unless $x==3; print "x not 3\n" if $x!=3; print "x not 3\n" if !($x==3);
    Usually the "if version" is more clear. However in the above, since $x is seldom exactly 3, "unless" focuses on the usual action with Perl's ability to put the "action" first and the conditional last. For longer blocks, most often use some form of "if".
      I will Marshall . Thanks for reply
      Lost in translation