I have a subroutine to which I want to pass a hash by reference. In the
real program, the hash in the caller starts out empty, and the
subroutine adds values to it.
 
The hash eventually becomes quite large, so I want the subroutine to add
values to the caller's hash. The following sample code does this, BUT I
have a concern that the subroutine might be making a local copy of the
caller's hash.

The code below shows how I am doing it now. It appears to work as
intended, but how can I ensure that the sub is not making a local copy
of the hash??

Thanks in advance:

use strict;
use warnings;

my %numbers = ();

makeNumbers(\%numbers);

foreach my $key (keys(%numbers))
{
  print "$key  $numbers{$key}\n";
}

#-------------------------------
sub makeNumbers
{
  my @numbernames = qw(zero one two three four five);

  if (my $nums = shift)
  {
    for (my $i = 0; $i < 6; $i++)
    {
      ${%{$nums}}{$i} = $numbernames[$i];
    }
  }
}
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to