> -----Original Message----- > From: Connie Chan [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 15, 2002 9:56 AM > To: [EMAIL PROTECTED] > Subject: require v. use > > > As what I've learnt, 'use' is working during the compile time, > where 'require' works at runtime, however, I have problem on > understand this.. > > ### code ### > sub A > { my ($case) = shift; > if ($case == 0) { require "lib0.pl" ; use somePm; use > anotherPm ; &doSth(...) } > if ($case == 1) { require "lib1.pl" ; use somePm; use > anotherPm ; &doSthEls(...) } > if ($case == 2) { require "lib2.pl" ; use somePm; use > anotherPm ; &doSthAnotherEls(...)} > } > > sub B > { my ($case) = shift; > # something similar to A > } > > sub C > { my ($case) = shift; > # something similar to A > } > > ### EOF Code ### > > Say, if above is called by require, then I think it probrably > those inline reqire and use > are calling when the sub is called and when the case is > matched... however, what > about the above finally becomes a .pm would those use, > require will be loaded once > I use the above pm ? > > I do really concern about the loading of system... so which > is a better method for lower > the loading ? I think exporter can help to lower some > loading, but how about those.... > Sorry, I don't know how to phrase the question... =), unless > I have some more clear > concept on what is the real practise of runtime and compile time...
First of all, read: perldoc -q require For a detailed explanation of the differences. Second, the run-time use of require would "generally" be used when there are multiple modules that can do the job, or there is some "optional" feature in your program that can be activiated if a given module is present. Consider the CPAN module. It will download tarballs using LWP if you have that installed. If not, it will try Net::FTP. (And if you don't have that it will try other things...) For techniques to optimze the load time of your modules, you can explore the SelfLoader (and possibly AutoLoader) modules: perldoc SelfLoader perldoc AutoLoader Of course, you should also avoid creating huge "do-everything" modules and break your modules up into logical groupings that allow you to avoid having to compile chunks of stuff you won't be using... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]