in reply to Re^2: Simplify code in Perl with "unless" loop
in thread Simplify code in Perl with "unless" condition
And yes "unless" is just the "NOT of if". These are all the "same".
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".#!/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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Simplify code in Perl with "unless" loop
by Chaoui05 (Scribe) on May 27, 2016 at 16:28 UTC |