Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Taken out of Contextby japhy (Canon) |
on May 23, 2001 at 20:51 UTC ( [id://82621]=note: print w/replies, xml ) | Need Help?? |
<merlyn>First, I point you to an article I wrote.</merlyn>
Basically, doing *alias = \$name makes $alias and $name the same thing. Thus, doing *alias = \*name is making all things with a symbol name 'alias' the same thing as those with the name 'name' (in some specific package, let's say main::). The wonderful thing about globs is that they can be used where references are expected: @{ *foo } is like @{ \@foo }. Thus, you can use a glob where you would ordinarily use a reference to a glob. That means that you can say *alias = *name instead of *alias = \*name. Another reason that *alias = *name works the same way as *alias = \*name is because you can assign a string to a typeglob: So, since a glob in scalar context is its "name", you can assign that name to a glob.
P.S. You can't say \*alias = ..., since you can't assign to a reference of something (that's why \$foo = \$bar doesn't work).
In Section
Meditations
|
|