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

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

Replies are listed 'Best First'.
Re^9: Modernizing the Postmodern Language?
by jcb (Parson) on Jul 06, 2020 at 01:03 UTC

    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