Difference between unless () return ... ,and return ... unless()

perl

Solution

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.

Problem

In Perl, is there any meaningful difference between: ``` return $result unless ($exist_condition); ``` and ``` unless ($exist_condition) return $result; ```

Original source