develooper Front page | perl.perl5.porters | Postings from October 2016

Re: (\@a) = \($x,$y) in non-void context

Thread Previous | Thread Next
David Nicol
October 20, 2016 02:27
Re: (\@a) = \($x,$y) in non-void context
Message ID:

example #9 in perldoc undef

        my ($x, $y, undef, $z) = foo(); # Ignore third value returned

seems to indicate option 3, but on reflection it is also consistent
with current behavior:

Let's say while instrumenting some working code, you want to keep the
first, second and fourth values returned from foo() by inserting code


to make

        consumes_foo(my ($x, $y, undef, $z,@more_if_any) = foo())

without breaking the system.

With current behavior, you can do that. With option 3, an explicit
$dummy is required.

Although this object might be better achieved with
        consumes_foo(my @instrumented_foo_result = foo())

except -- what if the the third value is a RAIL resource object, and
correct operation depends on its timely destruction within
consumes_foo(...)? In that case, passing through the third value as an
alias is clearly nifty. Option 3 would require rewriting, to save
current behavior where relied on, to some opaque monstrosity like

        my @foo_instrumentation;
        consumes_foo(do {
              @foo_instrumentation = my @foo_complete = foo();
               delete $foo_instrumentation[2];
               @foo_complete });

>> 1. (...,undef,...) = (...) autovififies a new undefined scalar value
>> then assigns the RHS value to it, returning the new scalar;
>> 2. it skips the assignment for that slot, and returns the RHS element;
>> 3. it skips the assignment for that slot, and returns &PL_sv_undef
>> (which will croak if later modified);
>> 4. it skips the assignment for that slot, and returns a fresh undef
>> scalar.
>> (2) is the current behaviour. I'd like to change it to (3).

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About