the *$datam = sub{#code} part is new to me. This is a data-type glob correct?

Actually, this question has nothing to do with OO.

Yes, you are assigning to what is called a "typeglob", which is sort of a record of all datatypes associated with the name of a global variable (thus $a, @a, %a, ... — all globals, of course, lexicals are different) and yes, that part is magical in that only the slot in the typeglob is affected that agrees with the type of reference that you are assigning to it. In other words, if you assign a scalar reference, only the scalar part of the typeglob will be affected, and array, hash, filehandle... all will keep their old value.

The best explanation that I recall having read, is in the O'Reilly book "Advanced Perl Programming", p.47. The author calls it "selective aliasing".

Witness:

@a = qw(a b c); $foo = "hello"; *a = \$foo; print <<"END"; array: @a scalar: $a END
Result:
array: a b c
scalar: hello

Not only that, but it's also a way to create variable's aliases:

$foo = "hello"; *a = \$foo; $a = "bye"; print "$foo\n";
Result:
bye
So I changed the value of the alias $a, and the original variable $foo changes with it. Both $a and $foo actually refer to the same variable internally.

That would also work if $foo is a lexical (my) variable.


In reply to Re: Help understanding perltooc examples? by bart
in thread Help understanding perltooc examples? by injunjoel

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.