in reply to Re^3: Assigning to the CODE slot of a GLOB whose REF is held in a lexical?
in thread Assigning to the CODE slot of a GLOB whose REF is held in a lexical?
As a foreward, I hope you don't get the wrong idea about my replies. I'm not trying to beat the point into the ground, I'm just trying to figure out exactly what's going on. If you're getting tired of this thread, feel free to ignore my reply.
You're explicitly overwriting the globref with a scalar. <P.You need to use the right syntax to assign to the SCALAR slot of the referenced glob.
Well, this doesn't overwrite the glob reference with a scalar reference:
my $globref = \*GLOB; *$globref = 1; print $globref, "\n"; # prints GLOB(0x.......)
But you're right that I'm not using the right syntax. I really meant to do this (which works as expected):
my $globref = \*GLOB; *$globref = \1; print $globref, "\n"; # prints GLOB(0x.......)
Compared to this (which overwrites the entire glob reference, strangely):
my $globref = \do { local *GLOB }; *$globref = \1; print $globref, "\n"; # prints REF(0x.......)
If I return the reference to the localised GLOB from with the do block, then everything works fine
Hmm, I thought about trying this, but got distracted. I'm glad you thought to try it for me. ;-) Perhaps it's something with the way local is returning the glob?
As I understand it, localising the GLOB effectively give you access to a new (anonymous) typeglob
That's what I thought when I first saw you use the idiom, but now I'm not sure what's going on. If you find out, please let me know. This is very curious. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Assigning to the CODE slot of a GLOB whose REF is held in a lexical?
by BrowserUk (Patriarch) on Nov 17, 2004 at 23:33 UTC | |
by revdiablo (Prior) on Nov 18, 2004 at 01:13 UTC |