> From: Jan Dubois <[EMAIL PROTECTED]>
> On Mon, 21 May 2001 18:15:02 -0400, "Arthur Cohen" <[EMAIL PROTECTED]>
> wrote:
>
> >: >
> >: >sub add2hash2 {
> >: > # refer to data indirectly using local (my) hash
> >: > my $thRef = shift @_;
> >: > my %th = %$thRef;
> >:
> >: You are making a *copy* of the original hash here.
> >
> >This is the part that puzzles me. I understand *how* it's working but
> >not why.
> >
> >What I'd *like* to do is simply declare a local variable to manipulate
> >the same hash that lives at $thRef (instead of having it populate a copy
> >of the original hash). Simply to make the syntax within the function a
> >little clearer. Is this possible? (under -w and use strict?)
>
> It is not possible to declare a "local" hash that is an alias to the one
> passed in as a reference; it is always a new hash. Even a scalar is
> always a new variable. The only way to modify scalar parameters directly
> and not through a reference is by accessing them through @_ (which
> contains aliases, not references to the original parameters).
Well, it is possible (and Jan sure knows it. He just doesn't want to
scare you out :)
If you play with typeglobs you may create such an alias :
sub add2hash2 {
# refer to data indirectly using local (my) hash
my $thRef = shift @_;
local *th = $thRef;
$th{'bee'} = 'hive';
}
Notice though that there is "local" not "my" now. You'd better
understand the difference.
Read : Coping with Scoping by M-J. Dominus
http://www.plover.com/~mjd/perl/FAQs/Namespaces.html
Jenda
== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
: What do people think?
What, do people think? :-)
-- Larry Wall in <[EMAIL PROTECTED]>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl