• refaliasing

    From Rainer Weikusat@21:1/5 to Rainer Weikusat on Thu Oct 15 17:16:55 2020
    Rainer Weikusat <rweikusat@talktalk.net> writes:
    Rainer Weikusat <rweikusat@talktalk.net> writes:
    Perl meanwhile supports feature called "refaliasing". This essentially
    provides the inverse operation to "creating a referenc", eg

    [...]

    I think this is a very handy addition in situations where the same
    reference would otherwise need to be dereferenced multiple times.

    Example of that would be a non-trivial method as this enables access the object representation without indirections.

    Example for this:

    ---------------
    \$valid = \$$self[VALID];

    {
    if ($valid) {
    $valid = 0, last if $$self[FORCE];
    $valid = 0 if has_changed($$self[VALS], \@new_vals);
    }
    }

    unless ($valid) {
    if (($err_title, @err_msg) = $$self[VALIDATE]->(@new_vals)) {
    err_box($err_title, @err_msg);

    $self->set_vals(@new_vals);
    $valid = 0;

    return;
    }
    }
    -----------------

    After the assignment in the first line, $valid "is" the same scalar as $$self[VALID]. This not only avoids a significant amount of "line noise" characters but should also be faster as 2 levels of indirection have
    been avoided (didn't test this and doesn't matter for this code).

    I hope this becomes "unexperimental" soon ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)