In Perl, is there any meaningful difference between:
return $result unless ($exist_condition);
and
unless ($exist_condition) return $result;
The second is a syntax error. I presume you meant
# unless statement modifier
return $result unless $exist_condition;
and
# unless statement
unless ($exist_condition) { return $result; }
They're virtually the same. One difference is that the unless statement creates a scope (two actually), while the unless statement modifier does not.
>perl -E"my $x = 'abc'; unless (my $x = 'xyz') { return; } say $x;"
abc
>perl -E"my $x = 'abc'; return unless my $x = 'xyz'; say $x;"
xyz
In practice, that will probably never come up, so the difference is merely a question of style.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With