in reply to Dereferencing a reference to a typeglob?

You are most likely confusing two technologies, please tell us what you try to achieve.

Typeglobs are actually difficult to handle because they introduce more magic than normal references.

Most Perl users probably never need them , since with lexical variables - i.e. declared with my - they are useless.

Typeglobs are helpful to manipulate the symbol table, but this is already "meta" stuff.

I think you just need to read perlref for how to handle references of lexicals.

Please don't apply Perl4 documentation to Perl5, Perl4 didn't have lexicals, that's why typeglobs were used there for referencing / dereferencing of globals and "aliasing".

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re: Dereferencing a reference to a typeglob?

Replies are listed 'Best First'.
Re^2: Dereferencing a reference to a typeglob?
by BrowserUk (Patriarch) on Oct 29, 2016 at 09:47 UTC

    Hm. There are still plenty of places where references to typeglobs are relevant in Perl5:

    1. File handles: Even lexical file handles are references to an underlying typeglob:
      open my $fh, '>', 'fred.junk'; Dump( $fh );; SV = RV(0x3c728b0) at 0x3c728a0 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x3c72950 SV = PVGV(0x3c82d38) at 0x3c72950 REFCNT = 1 FLAGS = () NAME = "$fh" NAMELEN = 3 GvSTASH = 0x36bde0 "main" GP = 0x3c93298 SV = 0x0 REFCNT = 1 IO = 0x3c72168 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x0 CVGEN = 0x0 LINE = 1 FILE = "(eval 18)" FLAGS = 0x0 EGV = 0x3c72950 "$fh"
    2. Directory handles: Even lexical ones:
      opendir my $dir, '.'; Dump( $dir );; SV = RV(0x2762e8) at 0x2762d8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x3c721e0 SV = PVGV(0x3c82d38) at 0x3c721e0 REFCNT = 1 FLAGS = () NAME = "$dir" NAMELEN = 4 GvSTASH = 0x36bde0 "main" GP = 0x3c93298 SV = 0x0 REFCNT = 1 IO = 0x3c72198 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x0 CVGEN = 0x0 LINE = 1 FILE = "(eval 22)" FLAGS = 0x0 EGV = 0x3c721e0 "$dir"
    3. Coderefs: Every time you call, or cause to be called, a subroutine indirectly:
      sub cmp { $_[0] <=> $_[1] };; Dump( \&cmp );; SV = RV(0x2762e8) at 0x2762d8 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x3c72858 SV = PVCV(0x3c5a028) at 0x3c72858 REFCNT = 2 FLAGS = () COMP_STASH = 0x36bde0 "main" START = 0x3d0ef48 ===> 0 ROOT = 0x3d0eed0 GVGV::GV = 0x3c721f8 "main" :: "cmp" FILE = "(eval 9)" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 1935 PADLIST = 0x3c72840 PADNAME = 0x3c72828(0x3cf7358) PAD = 0x3c72210(0x3cf7618) OUTSIDE = 0x36beb8 (UNIQUE)

    Being dismissive of these more obscure but still totally current and relevant areas of Perl because you rarely interact with them directly or don't understand them is of no help to anyone.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks for proving my point.

      All of this can be handled without manipulating the symbol table or using the *star operator.

      Showing advanced techniques like *a=\&func where a function ref is mapped to a special "slot" of a very unique data structure called "typeglob" residing in the symbol table is contra productive for a beginner.

      Especially if he just wants to learn dereferencing of lexicals.

      It's enough hinting that there are use cases in meta programming Perl.

      > because you rarely interact with them directly or don't understand them is of no help to anyone.

      Thanks again for the provocation.

      But I'm not going to play and you already know my opinion about you.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      UPDATE

      deleted honorary title ...

        Showing advanced techniques like *a=\&func ...

        I didn't show that "advanced technique" in either of my posts. You are the only one to use it in the entire thread!

        ... for a beginner.

        No where did the OP identify himself as a beginner; nor did anything in his post lead me to believe he was.

        Especially if he just wants to learn dereferencing of lexicals.

        And there is the crux of your misreading. He specifically asked about "Dereferencing a reference to a typeglob?" It is, all said and done the title of this thread!

        So, you misread his question; adjudged him to a beginner on no basis at all; and then condescendingly told him he was asking the wrong question.

        If my answering the question he asked, and pointing out your error, makes me a "pope troll", then I'll leave it to others to arrive at their own conclusions about your invaluable contributions to this thread.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.