my $return = mailoff($myvar); sub mailoff { my $var = $_[0]; #do stuff return $vartoreturn }
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).mailoff(@array); sub mailoff { my @array = @_; } .. mailoff(%hash) sub mailoff { my %hash = @_; }
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 reply to Re: passing variables between subroutines
by g0n
in thread passing variables between subroutines
by budreaux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |