Want 0.05

robin on 2001-08-29T12:33:54

In Perl 5.6.1 and later, there are some quite strict compile-time checks on the return value from an lvalue subroutine. Because the checks are done at compile-time, it doesn't matter if you know at run-time that you're going to be in lvalue context.

So code like:

sub foo :lvalue {
  if (want('RVALUE')) {
    return 23;
  } else {
    $foo;
  }
}

won't even compile. The new version of Want adds a function rreturn which you can use for an rvalue return from an lvalue sub. So the above can be written as:

sub foo :lvalue {
  if (want('RVALUE')) {
    rreturn 23;
  } else {
    $foo;
  }
  return;
}

The compiler sadly doesn't realise that rreturn will actually return from the function, so you have to put the bare return; at the end to shut it up. But you can think of that like the 1; that you have to put at the end of a module: meaningless furniture that has to be there.

Actually, the check is obviously too strict, because something like:

sub foo :lvalue {
  if (something_bad()) {
    die "Something bad happened";
  } else {
    $foo;
  }
}

ought to be okay. But in Perl 5.6.1 it won't compile. Can't modify die in lvalue subroutine return. I'm not trying to modify it, you brain-damaged compiler!