Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 $!;

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 :)


    "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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194698]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-06-24 00:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.