in reply to How can I use the values which is passed as arguments?
perldoc perlsub says:
The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like.It is customary to pick up the parameters (which are in the @_ array) as the first instruction inside the sub as follows:
or, if you do not know how many parameters will be passed:sub fun { my ($first, $second, $third) = @_; }
You can work directly with the @_ array but as its values are an alias to the paramaters passed in, you could unwillingly be changing the original variables and cause some subtle and difficult to trace bugs.sub fun { my @parameters = @_; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I use the values which is passed as arguments?
by anbutechie (Sexton) on Mar 10, 2009 at 07:47 UTC | |
by GrandFather (Saint) on Mar 10, 2009 at 08:05 UTC | |
by anbutechie (Sexton) on Mar 10, 2009 at 08:27 UTC |