hi barry --   

In a message dated 12/1/2009 5:34:34 PM Eastern Standard Time, 
[email protected] writes:

> I have a situation where I specifically want to pass the name of an
> array to a subroutine, and allow that subroutine to modify values in
> the caller's copy of the array.

this is called a 'symbolic' or 'soft' reference, and is in contrast to a 
'hard' reference.   as you will see if you look through your hard copy 
references and through perlref and perlreftut on-line, symbolic references 
are generally considered a Bad Thing for reasons that have been touched 
upon in other responses.   the use of hard references is considered a best 
practice for the best of reasons.   

however, there a time and place for everything.   take a look at the code 
below; if you understand and feel comfortable with it (and think your 
maintainers will as well), go ahead and use symbolic references.   but 
heed well the many warnings against such things!   

>perl -wMstrict -le
"our @array1 = qw(A B C);
 print_ra('array1');
 print_ra('array2');
 our @array2 = qw(D E F);
 print_ra('array2');
 { my @array2 = qw(x y z);
   print_ra('array2');
   }
 sub print_ra {
   my $array_name = shift;
   no strict 'refs';
   print qq{print_ra: (@{ $array_name })};
   }
"
print_ra: (A B C)
print_ra: ()
print_ra: (D E F)
print_ra: (D E F)

good luck, and choose wisely -- bill walters   

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to