in reply to Re: Re: lvalue subs return undef, playing with experimental features, the End of the World, etc
in thread lvalue subs return undef, playing with experimental features, the End of the World, etc
This isn't terribly helpful, is it? Yet it does illustrate how you are just supposed to leave it there. Perl subroutines normally work such that the last thing left on the stack gets returned, but in the case of an lvalue-enabled subroutine, there must be a special handler that converts the stack entry into a kind of reference which can be assigned to.my $val; sub canmod : lvalue { $val; } sub nomod { $val; }
First, figure out what you need to return, taking as much time as is necessary. Then, once you know, shuffle the appropriate variable to the top of the stack and leave it there.my %foo; my $bar; sub foo : lvalue { my ($key) = @_; if (some_complex_condition()) { do_some_stuff($foo{a}); $key = "b"; } if (other_complex_condition()) { $foo{a} .= do_some_other_stuff($foo{b},$foo{c}); $key = "a"; } defined($key)? exists($foo{$key})? $foo{$key} : $foo{$key} = undef : $bar; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Formatting chained and nested ternary ops (was Re^4: lvalue subs return undef....)
by demerphq (Chancellor) on May 07, 2002 at 11:40 UTC |