Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
In reality, the syntax *{"color"} references the symbol table entry as a whole, not the GLOB slot of it

So if you write something like:

*color = *other;

does *other go in the GLOB slot?

It sounds like what people are saying is that perl treats the syntax here:

 *{"color"} = ...

differently than the rvalue syntax here:

@arr = @{"color"};

and in the first case the braces aren't dereferencing anything. So is the syntax:

 *{"color"} =

just a way to use a string when constructing a typeglob's name? Somewhat like the braces in the following code also aren't dereferencing anything:

my $color = "green"; print "${color}ery";
When you assign a reference to a glob, it gets assigned to the appropriate slot. *foo = []; assigns to the ARRAY slot; *foo = sub {}; assigns to the CODE slot.

Yes, I understand that aspect of typeglobs.

What makes you think they might be equivalent?
When I posted, I was not clear on what either syntax was doing. Now I understand that the braces in &{"color"} are an attempt to dereference a string, which means perl treats "color" as a "symbolic reference". To deal with a symbolic reference, perl must go to the symbol table and look up "color". Then the & preceding the braces tells perl to grab what's in the CODE slot for "color". As I understand things, that is in contrast to a hard reference, something like &{$some_coderef}, which directs perl straight to the address in memory where the subroutine is stored (bypassing the symbol table), and hence is more efficient.

But I'm still unclear on how perl interprets *{"color"}.

In reply to Re^4: typeglob/symbolic reference question by 7stud
in thread typeglob/symbolic reference question by 7stud

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2020-11-23 17:30 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found