Click to See Complete Forum and Search --> : *sigh* Perl modules and namespace


michboy
06-20-2002, 08:26 PM
Ok. I've got a CGI script, works fine. In the script, I needed to wait until a lot of things had happened to print out any HTML, but I needed to print HTML before things had happened. To solve this, I made an array of references to subroutines, and pushed the reference to the correct subroutine into the array whenever I needed something printed. Then, at the end of the file, I went through the array and dereferenced each element, calling the subroutine it referenced. It worked fine.

But I decided I'd like to put all these subroutines in a module. I'm new at modules. So I did this and found out I was trying to print variables that were local to main. I've tried all kinds of things to get around this. My best attempt came by pushing each variable I needed to print into another array that ran parallel to the array of references to subroutines, so I could call the subroutines with its corresponding variable. It didn't work...it said that I wasn't passing references to an array, which I was.

So, what I want to know is, is there a way to access main's variables from a module? By now I know it's just going to be easier to keep the subroutines in the file, but I would still like to know.

Sorry if this post made your brain hurt....mine sure does.

michboy
06-20-2002, 09:10 PM
Nevermind. I was using 'my' and I needed to use 'local' for the vars I wanted to use in the module. Then, in the module, just call it using main::, obviously.