in reply to Re: subroutine syntax
in thread subroutine syntax
Perl has, like many other languages global variables. So you don't *need* to pass a variable to a subroutine in order for the subroutine to "see" that variable. However, in subroutines, relying on globals to be set, and modifying them is a recipe for disaster. It may be OK in small scripts, but when your scripts grow you'll curse the decision to use globals more often than not (see tilly's post RE (tilly) 3: redeclaring variables with 'my' for a very good explanation of why "going global" without good reason is a bad idea). The general rule is: you pass variables to your subroutines, and then you localize them using my, as other monks in this thread have shown you (snax's suggestion for other reading material is where you should start). I'm not going to reproduce the perl documentation -- read up on the my operator and please don't confuse it with the local operator =)
|
|---|