PDA

View Full Version : if used four times, does a sub run four times?


bazz
07-26-2005, 01:48 PM
Maybe I'm overthinking here but....

I want to use the data gathered by a sub, on four occasions. Does this mean that the sub will run four times or can perl cache the data from the first sub-run and use it throughout the script?

Bazz

FishMonger
07-26-2005, 04:29 PM
If you put the data into global vars, you can use it anywhere, anytime, as many times as you want within the execution of the script.

bazz
07-26-2005, 05:24 PM
Thanks FishMonger. :thumbsup:

Jeff Mott
07-26-2005, 07:10 PM
Though if the program gets large enough, accumulating lots of global variables can start to make the code a bit sloppy. If you need to have data persist across subroutine calls then you might want to consider taking an object oriented approach.

bazz
07-26-2005, 07:32 PM
Thanks Jeff, I'll google that and see what it entails.

Bazz