Module or Library File
Posted by TedH (TedH), 30 April 2008Hi. One of the things I use often are files containing sub routines that are used in a variety of scripts. Each script requiring a reusable sub simple calls the sub from the "required" lib file. I usually name the file as a filename.lib.
Another way of reusing code is a Perl Module. My question is: Which is better?
Do modules behave differently than library files?
Like, are they better when a lot of different scripts might use them at near the same time?
Or is there really not much difference at all?
I realize I will have to look at different modules to see how stuff is written in the module and then used in a script - thought I'd say that to save you telling me I've also downloaded a few tutorials (but they tend to go around the world to cross the road on some points).
Cheers - Ted
Posted by admin (Graham Ellis), 1 May 2008In essense, a use is a require that's run at the time the code is being compiled rather than as it is being run. (i.e. it's a require in a BEGIN block)
This means that you can use require code to optionally load things, but use code comes in at compile time, even if it's in the middle of a conditiional block of some sort. And because use comes in at compile time, it can be used to define bare words and pragmata that effect the rest of the compile.
Hopefully haven't given you a complete world tour there, Ted!
Posted by TedH (TedH), 1 May 2008Hi Graham;
I think I've got it.
What I have is an admin script where some code elements are repeated at different points in different sub-routines. I thought that if I used a library file with the repeated code in (as individual subs) and simply called the subs as needed, I could cut things down size wise. It does work that way (I haven't broken it yet so it seems to be okay). I was concerned about its overall efficiency and figured if I make a localized module it might help.
Hopefully haven't given you a complete world tour there, Ted! Nah, just a pleasant stroll through the wood to the stuff that was already on the other side of the trees anyways.
Cheers - Ted
This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho