text: note tobyink <p><c>*answer_comments</c> is a glob - basically an entry in Perl's symbol table. It is kind of a bundle which contains <c>sub answer_comments</c>, <c>our $answer_comments</c>, <c>our @answer_comments</c>, <c>our %answer_comments</c> and the <c>answer_comments</c> bareword file handle.</p> <p>If you assign one glob to another, like <c>*xxx = *yyy</c>, then it makes <c>sub xxx</c> and <c>sub yyy</c> aliases for each other, and <c>our $xxx</c> and <c>our $yyy</c> aliases for each other, etc.</p> <c> use 5.010; use strict; use warnings; our ($xxx, $yyy, @xxx, @yyy); *xxx = *yyy; # alias $xxx = 42; say $yyy; # says "42" @xxx = (9,9,9); say "@yyy"; # says "9 9 9" </c> <p>Anyway, that's what happens when you assign one glob to another glob. But you can also assign references to a glob, in which is doesn't alias the whole bundle, but just the relevant slot within the glob. For example:</p> <c> use 5.010; use strict; use warnings; our ($xxx, $yyy, @xxx, @yyy); *xxx = \$yyy; # alias $yyy, but not @yyy $xxx = 42; say $yyy; # says "42" @xxx = (9,9,9); say "@yyy"; # says nothing </c> <p>And so <c>one_param</c> returns a coderef, and we can assign it to the glob:</p> <c> *answers_comments = one_param("answers","comments"); </c> <p>This effectively installs the sub into the package with a given name. <i>Almost</i> as if you'd done:</p> <c> package ...; sub answers_comments { ...; } </c> <p>(This is what [mod://Exporter] does internally - that module is not as magic as it seems.)</p> <p>I say "almost" though. There's one key difference, and that's what the CPAN module [mod://Sub::Name] takes care of. When the <c>answers_comments</c> method is called, Perl still internally treats it as an anonymous coderef. Which means that stack traces (e.g. [mod://Carp]) would show it as "__ANON__" rather than "answers_comments".</p> <p>Naming the sub is also important if you use something like [mod://namespace::autoclean] which deletes subs it finds in your package that don't look like methods. Naming a sub makes it look like a method.</p> <p>So Sub::Name is well worth using when you muck around with globs; it's a shame it's not bundled with Perl.<4174 1014194