in reply to Re^2: Label makes a sub to return empty list -- "secret"? documented?
in thread Label makes a sub to return empty list -- "secret"? documented?

I would have expected the empty return to have been optimized away during compilation two decades ago at least.

Jenda
1984 was supposed to be a warning,
not a manual!

  • Comment on Re^3: Label makes a sub to return empty list -- "secret"? documented?

Replies are listed 'Best First'.
Re^4: Label makes a sub to return empty list -- "secret"? documented?
by LanX (Saint) on Sep 11, 2025 at 23:04 UTC
    well B::Deparse would fail then ...

    There is also benefit in consistent behavior.

    I'd rather prefer a second version of the sub construct (something like def ) which implements this, instead of relying on such syntax tricks.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Fail in what way? In not producing the exact (save for whitespace) copy of the original code? Is that really a problem? Both the compiled and "deparsed" code would still have to denote that the subroutine isn't returning the value of the statement before the empty return.

      Empty return is the only solution that is NOT a syntax trick, therefore it ought to be implemented efficiently and if B::Deparse needs to produce code of a subroutine that returns nothing, the empty return should be the "inferred" solution even if it means that deparsing turns some of those tricks into an explicit empty return.

      Jenda
      1984 was supposed to be a warning,
      not a manual!

        Yes probably.

        three issues worth mentioning:

        • a) Perl is not that orthogonal to be instantly sure these three variants always do the same thing.
        • b) P5P have bigger fish to fry than such micro optimizations.
        • c) maintaining B::Deparse is neither straightforward nor easy.

        Though if you think it's so important, you can submit a patch to optimize the last return away.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery