in reply to passing variables between subroutines
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".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: passing variables between subroutines
by Grygonos (Chaplain) on Jan 16, 2006 at 15:51 UTC | |
by revdiablo (Prior) on Jan 16, 2006 at 18:57 UTC | |
by Grygonos (Chaplain) on Jan 17, 2006 at 19:14 UTC | |
by blazar (Canon) on Jan 17, 2006 at 10:45 UTC |