[stuff cut out]

>> For example, if I'm populating a complex variable @d with
>> lots of pointers,
>> hashes, arrays, etc. within, if I populate that within a
>> subroutine, how do
>> I get it back out conveniently without it making a whole
>> nother copy of it
>> outside?  If it's 500 MB, isn't that horribly inefficient?
>> Plus, I have to
>> keep track of it.
>> 
> You pass as a refernce as ni
> called_sub(\...@d);
> Now when you update, you are updating @d and not a copy.
>  
>          If you have any questions and/or problems, please let me know.
>          Thanks.
>  
> Wags ;)
> David R. Wagner


So let's say I pass a reference to an array:

   my @d = (1,2,3);
   called_sub(\...@d);

... but then in called_sub, accessing that gets a lot "noisier", right?

   sub called_sub {
       my $d = shift;
       push @{$d}, 2;  # I'd rather be able to use @var instead of @{$var}
   }

Is there any way to make a new variable, @something, that is just another
name for the array that was passed in by reference?  Since I'm building a
complex data structure, having to include all those @{}'s can get annoying.

Also, if called_sub modifies that array that was passed in by reference,
does it stay changed outside the subroutine?  Or do I have to return
something from the subroutine and capture it on the outside?

Thanks!!

- Bryan

ps.  Out of curiosity, what does "wags" mean?



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to