in reply to Re^2: Returning and passing data to and from subroutines
in thread Returning and passing data to and from subroutines
If you call a sub with a single scalar, it's the same as calling it with a 1-element list. @_ will contain the one scalar, and you can get it with shift. If you want to call a sub with multiple arrays or hashes and not have them flattened, you need to use references, and you probably want to look at something like perlreftut. If you call a sub with a single array and you want to get all the elements out at once, you can use:
ormy @args=@_; # or my %args=@_ if you know it's going to be a hash
the second form there assumes you know how many arguments you're going to get, or don't care if some of them come back undef.my ($arg1, $arg2, $arg3) = @_; # faster than (shift,shift,shift)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Returning and passing data to and from subroutines
by vendion (Scribe) on Jul 21, 2010 at 04:05 UTC | |
by ssandv (Hermit) on Jul 21, 2010 at 15:34 UTC |