Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hey Andrew, this is just a belated reply concerning perl's argument handling. I'm typing this because I've got the feeling you've missed something there :-)
Perl subroutines get their arguments in the special @_ array, like this: this extends to any and all subroutine argument handling in perl - the only way to get a hold of arguments is to directly or indirectly read from the @_ array. shift() and pop() without further arguments do this implicitly: Note that your code above does not do anything with the supplied arguments, it just uses the variables as supplied in the global scope. that means that when the variables are modified in the subroutine, that also modifies the variables in the global scope and in the recursive calls, since they are all the same variable. Note also that this code: does not do the same as:
In the first example, the outer-scope $i is increased, while in the second example only the $i local to the inc() sub is increased. There's lots of pretty subtle and interesting stuff going on in this simple example. You might start by reading perlsub and/or searching for lexical variables and closures here on perlmonks. In reply to Re^3: Misunderstanding Recursion
by Joost
|
|