CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Handling own modules

 



MoaLaiSkirulais
New User

Aug 7, 2014, 8:50 PM

Post #1 of 4 (668 views)
Handling own modules Can't Post

hi all have i have a question using modules:

i developed my own module (package) for example "MyUtils.pm"
That is a file located on same folder than the main.cgi that use it. Then i use the module with "use MyModule"

I think that is a bit slow. Is there a way to "compile" the module and include it in perl core or something like that?

If yes, it will load and run "faster"?

thnx!


Zhris
Enthusiast

Aug 7, 2014, 9:26 PM

Post #2 of 4 (663 views)
Re: [MoaLaiSkirulais] Handling own modules [In reply to] Can't Post

cross posted on Stack Overflow.


BillKSmith
Veteran

Aug 8, 2014, 8:27 AM

Post #3 of 4 (648 views)
Re: [MoaLaiSkirulais] Handling own modules [In reply to] Can't Post

I doubt that there is anything you can do to make a module load faster. Optimizing your code to execute faster often helps, sometimes by a lot. It only helps to optimize the parts of the code that really are using a lot of time.
Identifying these parts requires profile tools. (Your intuition is a very poor guide)

The module that you have described will not load at all. "Module" and "package" are very different concepts. Package is a Perl construct for controlling the scope of global (not declared with a my) variables. A module
(in the sense that it can be loaded with use) is a file which contains perl code and whose name has the extension '.pm'. The code must contain a package whose name 'matches' the file name. In general, the last statement must be the single character '1'. The file must be stored in one of the folders where perl looks for modules. (This does not include the current directory by default. One fix is to add the directive use lib directive to your main program.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Aug 8, 2014, 8:59 AM

Post #4 of 4 (646 views)
Re: [BillKSmith] Handling own modules [In reply to] Can't Post


Quote
In general, the last statement must be the single character '1'. The file must be stored in one of the folders where perl looks for modules. (This does not include the current directory by default.


Sorry Bill, but that's not correct.

It's good that you qualified the first part of your statement by saying "In general", but the last statement does not have to be a '1'. It must evaluate to "true".

On all system that I use, the cwd is included when searching for modules even though it's not in the @INC array.

My synergy connection to my linux box just died but I'll post an example once I get it back up.


Quote
[root@099-91-RKB-2 ~]# cat MyModule.pm
package MyModule;

use strict;
use warnings;

return 2;

[root@099-91-RKB-2 ~]# cat test.pl
#!/usr/bin/perl

use strict;
use warnings;
use MyModule;

print $_,$/ for @INC;

[root@099-91-RKB-2 ~]# ./test.pl
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/5.8.8
.
[root@099-91-RKB-2 ~]# pwd
/home/rkb



(This post was edited by FishMonger on Aug 8, 2014, 9:11 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives