in reply to Re: unless versus if ( ! ) inside a subroutine
in thread unless versus if ( ! ) inside a subroutine

If we change
if ( ! $v ) { # ...
to
if ( $v ) { # ...
It still returns nothing. So it appears with 'if', it does not return the value evaluated inside the conditional. But why?

Replies are listed 'Best First'.
Re^3: unless versus if ( ! ) inside a subroutine
by Anonymous Monk on Jan 15, 2008 at 17:06 UTC
    How about trying explicit returns?
    sub testUnless { my $v = 'Navidson'; unless ( $v ) { return undef; } else { return $v; } } sub testIfNot { my $v = 'Holloway'; if (!$v) { return undef; } else { return $v; } }
    You have to understand that Perl will return the last evalution from a sub if you are not explicit. So start being explicit!
      The question is not on recommended practices to fix a problem but rather the perl internals regarding if and unless.
      A reply falls below the community's threshold of quality. You may see it by logging in.