Hi John.

I may be misunderstanding you, but this doesn't look right to me.

John W. Krahn wrote:
> Jeroen Lodewijks wrote:
> >
> > 1)
> >
> > sub PassHash
> > {
> >     my (%hash) = @_;
> >
> >     $hash{$some_key} = 'test';
> >    ...
> > }
> >
> > PassHash(%hash);
> >
> > What happens internally?
>
> perldoc perlsub
>
> > Will the whole contents of the hash be copied in memory?
>
> Yes, the statement "my (%hash) = @_;" copies the list passed to
> PassHash() into the hash %hash.
>
> > Or is only a reference passed?
>
> If you use the contents of @_ directly then you are dealing with
> references to the original variables.

But not references in the usual sense. Perl passes the parameters
internally 'by address', so that within the subroutine the
elements of @_ are synonyms for the actual parameters. They are
not Perl references in any way.

> > Will the $some_key element show up after PassHash?
>
> Yes.

No. %hash is a lexical value which is initialised from the
parameter list at the start of the subroutine. Any changes
to this hash, like

  $hash{$some_key} = 'test'

are purely local to the subroutine and will vanish when it exits.


HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to