Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^6: Modernizing the Postmodern Language?

by LanX (Saint)
on Jun 30, 2020 at 23:44 UTC ( [id://11118745]=note: print w/replies, xml ) Need Help??


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

> The package/filehandle conflict is one of the few actual problems with bareword filehandles in Perl,

what about declared subroutines?

Without brackets they become barewords.

I find the whole, 4ish "how do I pass bareword FH to subroutines?" by "referencing of a glob" syntax like \*DATA extremely confusing.

I won't miss them.

I only wished I wouldn't find so many perldocs and modules on CPAN still advertising them in their POD.

And if you still insist on bareword FHs, you can still let a sub return them.

sub FH { return $fh; }

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

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

    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?

      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118745]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found