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.
In reply to (Ovid) RE(2): passing refs to subs
by Ovid
in thread passing refs to subs
by jptxs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |