Hi!
First of all, using unless with complex logic inside the condition,
especially using negatives (unless not...) is much harder to read and
understand than using if.
See http://stackoverflow.com/a/3048787 and of course see original adwise
from Conway's perl best practices
http://shop.oreilly.com/product/9780596001735.do
So unless is bad choice in your case, i adwise to use if.
Second, contitions if (defined $var) and unless (not $var) are not the
same, for example
use feature qw/say/;
my $var = 0;
if (defined $var) { say q[i'm in if]; }
unless (not $var) { say q[i'm in unless]; }
will print
i'm in if
28.03.17 23:58, Uri Guttman пишет:
On 03/28/2017 04:46 PM, SSC_perl wrote:
I could use another set of eyes on this. Could someone please
double check these two sets of conditions and let me know if the
first is equivalent to the second? I believe they are, but I don’t
want to take any chances.
# Both of these should be equivalent.
$out->{$field} =~ s/``/\r/g unless (not $out->{$field} or $field eq
'categories');
$out->{$field} =~ s/``/\r/g if (defined $out->{$field} && $field ne
'categories');
google for demorgan's theorem. you should know it if you deal with
complex boolean logic.
the only difference i see is using defined in the 2nd line.
also i would test $field ne 'categories' first as if that is true why
even test $out->{$field}? it is a slight optimization but may also
clarify the logic.
$out->{$field} =~ s/``/\r/g if $field ne 'categories' &&
$out->{$field} ;
no need for the () on statement modifiers so i removed them. i also
didn't use defined as any value other than 0, '' or undef will be true
and worth running the s///.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/