in reply to Database module question
i have to pass $dbh variable to a module to work, but this seams very unprofessional
Not at all! This is the way to do it. You do not want to have your module assume that somewhere else someone else did or did not set a variable. A subroutine should only use variables local to itself and received through the parameter list. I should then return a (list of) value(s) for the caller to pick up and not change some global values.
The so-called action at a distance will lead to all kinds of nasty and difficult to debug errors.
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
|
|---|