http://qs321.pair.com?node_id=869529


in reply to Re^3: typeglob/symbolic reference question
in thread typeglob/symbolic reference question

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"}.