Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: passing variables between subroutinesby g0n (Priest) |
on Jan 16, 2006 at 15:45 UTC ( [id://523525]=note: print w/replies, xml ) | Need Help?? |
If your variable is a simple scalar, you can pass it to the sub as follows:
If you want to pass arrays and hashes around, you can pass them as a list:
But a) you can only pass one array or hash that way, and b) it's a copy, not the original, so changes won't be seen in your main program (that's true in the first example as well, hence the return variable). Alternatively, you could look at perlref, and pass references around. There's some simple introduction to that technique in Why use references?.
-------------------------------------------------------------- "If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing." John Brunner, "The Shockwave Rider".
In Section
Seekers of Perl Wisdom
|
|