Thanks. I have read about modules and am aware of that particular method. The concern I have is this. The "module" I will be creating will contain about 40 functions for accessing data from a database. I would like to have all the functions I write to automatically be available instead of explicitly exporting all ~40 of them.
Should I assume then that there is not another preferred method of doing what I want to do?
Thanks,
disciple
| [reply] |
Well "preferred" doesn't really apply, but if you want to do what you are saying, just put "package main;" at the top of the 'module' instead of some other package name.
Your main program is package main, and by putting your module's subroutines into package main, they are automatically available for you without exporting.
You probably don't want to here this, but I'll reiterate what the docs and other commenters say. You should really do it the right way and segregate things into separate packages and export only symbols that need to be.
| [reply] |
Thank you for your response. This is exactly what I was looking for. I wanted to know if there was another way to do it, and you pointed out that there is, but that it is not recommended and therefore not the preferred way.
I am curious though, if every function is going to be available (exported) is there a reason not to put them in package main?
Thanks,
Glen
| [reply] |
You're saying the reason you don't want to use a module is because you don't want to copy and paste 40 function names into the @EXPORT array? I'd think you spent more time here trying to find a different way than it would have taken to copy and paste those function names to begin with.
| [reply] |
You are correct that in this instance I have spent more time here trying to find if there is a preferred way to do what I want to do. However, this is something I will be and have been doing on a semi-regular basis.
It is a maintenance issue as well. Everytime you add a function, you must add it to the export line. I don't want to do that but if there is no other preferred means of using functions from another file, then I will.
Besides, can you really blame me for asking if there is a quicker/easier way? Aren't we all looking to make our programming lives a bit easier?
| [reply] |