zergoid has asked for the wisdom of the Perl Monks concerning the following question:

Did you try it to see if/how it works?
What do you mean "try it". Run perl in gdb?
Firstly, there have been a number of editions of "Programming Perl". I own the first three: that code doesn't appear on page 86 of any of those. Note: This is true for many Perl books. Providing more information than just the title is usually very useful and will generally get a faster (and better) answer.
Sorry about that. That's the 4th edition.
The code you've posted is almost identical to that in "perldata: Typeglobs and Filehandles".
That chunk of perldata is copied from the book verbatim (or is it the other way around). Alright, forget about it.

Replies are listed 'Best First'.
Re: Local Typeglob
by hdb (Monsignor) on Feb 21, 2014 at 07:47 UTC

    This whole thread seems to be out of order. Have you removed your original question and replaced it with your response to the replies you got? This is unfortunate as it bereaves all of us of the opportunity to add our own responses or to learn from the discussion.

      Basically, the whole OP has been rewritten so reponses now make no sense.

      Originally, when I replied to it, it had something along the lines of:

      "I found this code in 'Programming Perl':"
      ... short piece of code ...
      "Question about use of typeglobs in that code"

      I front-paged it because it seemed to be an interesting question about typeglobs which we haven't seen that often recently.

      It's been considered for "Restore original content.". Hopefully it'll be fixed soon.

      -- Ken

Re: Local Typeglob
by kcott (Archbishop) on Feb 21, 2014 at 06:41 UTC

    G'day zergoid,

    Welcome to the monastery.

    Firstly, there have been a number of editions of "Programming Perl". I own the first three: that code doesn't appear on page 86 of any of those. [Note: This is true for many Perl books. Providing more information than just the title is usually very useful and will generally get a faster (and better) answer.]

    The code you've posted is almost identical to that in "perldata: Typeglobs and Filehandles". That documentation explains typeglobs, the code returning *FH and code (sub myopen {...}) to do this using a lexical (my) variable. It also contains links to further, related information.

    I'd suggest checking if your book also has similar, additional information (e.g. a myopen() routine). Even if it doesn't, the documentation I've linked to may answer your question or, at least, provide enough for more specific/focussed questions on some particular aspect of typeglobs.

    -- Ken

Re: Local Typeglob (try it)
by Anonymous Monk on Feb 21, 2014 at 06:41 UTC

    Did you try it to see if/how it works?

    FWIW, to answer the question, you'd have to ask the authors --- anyway, lexical vars are what its all about

    sub itref { \*STDOUT } sub itglob { *STDOUT } for my $it( itref(), itglob() ){ print $it qq{$it\n}; } __END__ GLOB(0x99b30c) *main::STDOUT