Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: local vs my

by Anonymous Monk
on Sep 03, 2002 at 07:53 UTC ( #194698=note: print w/ replies, xml ) Need Help??


in reply to Re: local vs my
in thread local vs my

That's right. Filehandles only ever exist as package "variables" in typeglobs. You have to localise them with local you can't create lexical filehandles with my

What about this?

open(my $fh, 'somefile') || die $!;


Comment on Re: Re: local vs my
Select or Download Code
Re: local vs my
by Arien (Pilgrim) on Sep 03, 2002 at 08:07 UTC

    What about this?

    open(my $fh, 'somefile') || die $!;

    When calling open with an undefined variable for the indirect filehandle ($fh in this case), open will stick a reference to the "real" filehandle in the indirect filehandle. $fh is a lexical, what it refers to is not.

    — Arien

Re: Re: Re: local vs my
by davorg (Chancellor) on Sep 03, 2002 at 08:10 UTC

    Excellent point. But that is, of course, a relatively new innovation :)

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      The innovation is only in the autovivification. It was awkwardly possible before as well, you just had to do the job yourself:
      use Symbol; my $fh = gensym; open $fh, $filename;

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-07-28 23:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (210 votes), past polls