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. :-)


In reply to Re^4: Assigning to the CODE slot of a GLOB whose REF is held in a lexical? by revdiablo
in thread Assigning to the CODE slot of a GLOB whose REF is held in a lexical? by BrowserUk

Title:
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, details, 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, summary, 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.