Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: local vs my

by Anonymous Monk
on Sep 03, 2002 at 07:53 UTC ( [id://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 $!;

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://194698]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-23 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found