Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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 making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2017-12-15 03:41 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (416 votes). Check out past polls.