in reply to Re^6: Modernizing the Postmodern Language?
in thread Modernizing the Postmodern Language?

I believe that sub would need to be:

sub FH { our $FH; return $FH }

So does this lead to a use filehandles pragma that will (mostly) work for declaring filehandles by establishing the proper subs?

Replies are listed 'Best First'.
Re^8: Modernizing the Postmodern Language?
by LanX (Saint) on Jul 04, 2020 at 20:22 UTC
    This

     sub FH :lvalue  { my $fh }

    should do.

    But I don't have the time to test it in all edge cases.

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

      You are correct about needing the :lvalue attribute, but if I understand correctly, my will create a new scalar every time FH is called.

      Another alternative could be: { my $fh; sub FH :lvalue { $fh } }, using the closure to capture a single instance of the lexical. TIMTOWTDI really works!

        you are right of course, a closure was my initial idea, dunno why I lost it here.

        FWIW state might be an alternative

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