Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
[NetWallah]: /stevieb I dont understand - the poster had a very legitimate issue, and expressed it clearly. WHat did you have a problem with?

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-02-23 14:57 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (347 votes). Check out past polls.