in reply to Taken out of Context
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.*foo = "bar"; print *foo; # *main::bar *foo = "this::that"; print *foo; # *this::that
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).
japhy --
Perl and Regex Hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Taken out of Context
by Petruchio (Vicar) on May 23, 2001 at 23:16 UTC | |
by japhy (Canon) on May 23, 2001 at 23:24 UTC | |
|
(bbfu) (article bug) Re (2): Taken out of Context
by bbfu (Curate) on May 24, 2001 at 05:00 UTC |