in reply to Re: passing refs to subs
in thread passing refs to subs
Also, remember using reference allows you to modify the actual variable, where normally you will just modify a copy.
I'm sure you understand what really happens in a sub, but your wording is a bit vague, so I'll clarify this for monks who might not be familiar with this issue.
You will only modify a copy of a variable passed to a sub if you copy the arguments to new variables. If you modify the @_ array directly, you modify the original variables. Run the following snippet to see what I mean:
#!/usr/bin/perl -w use strict; my $test = "Hi there!"; change($test); print $test; sub change { $_[0] = "Hey, this is different!\n"; }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|