On Mon, 21 May 2001 17:39:21 -0400, "Arthur Cohen" <[EMAIL PROTECTED]>
wrote:
>sub add2hash {
> # refer to data directly using hash reference
> my $thRef = shift @_;
> $thRef->{'worker'} = 'ant';
>}
>
>and call this like so:
>
>&add2hash(\%hash);
You may want to investigate function prototypes:
sub add2hash (\%) {
# refer to data directly using hash reference
my $thRef = shift;
$thRef->{worker} = 'ant';
}
and call it like this:
add2hash(%hash);
>All very well and good. But for some reason, the first thing I tried
>didn't work. That was to write a function like this:
>
>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.
> $th{'bee'} = 'hive';
You change the *copy*, not the original now. You would need to copy
everything back now:
%$thRef = %th;
But don't do this! It will be very slow when the hash gets large. Using
hash references is fine! :)
>}
-Jan
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl