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: Advanced:
Need help about preventing overloading a script!

 



pozvanete
Novice

Mar 22, 2009, 9:54 AM

Post #1 of 4 (1464 views)
Need help about preventing overloading a script! Can't Post

Hi all,

I am trying to figure out the best organisation of usage a custome purpose module library. I have no experience on this end so please.

The number of modules in this library will change, mostly increase.

The user of the main script will have a choice to add them.

If I place the entire 'use lib' - will this be a burdain on the script if the modules become 100? Is the 'if' statement prevents that.

What is the common practice! advice appreciated.

I hope the example bellow is clear. &1 and &2 are subroutines in the script.





if($content eq '1'){&1;}
elsif($content eq '1'){ &2; }
elsif($content eq 'other3'){ use other3 ; &other3() ; }
elsif($content eq 'other4'){ use other4 ; &other4() ; }
elsif($content eq 'other5'){ use other5 ; &other5() ; }
...........................................................


KevinR
Veteran


Mar 22, 2009, 10:54 AM

Post #2 of 4 (1463 views)
Re: [pozvanete] Need help about preventing overloading a script! [In reply to] Can't Post

You can't conditionally load a module with "use" the way you are attempting to do it. You can use "require" instead of "use", you can also look into "autoload" or the "if" pragma. "require" should be the easiest to impliment.
-------------------------------------------------


FishMonger
Veteran / Moderator

Mar 22, 2009, 8:10 PM

Post #3 of 4 (1455 views)
Re: [pozvanete] Need help about preventing overloading a script! [In reply to] Can't Post


Quote
If I place the entire 'use lib' - will this be a burdain on the script if the modules become 100?


That tells me that you have a poorly designed script and modules.

I have never seen a valid example where the possibility of using (or require) upto 100 modules would be a valid approach.

If you present a more complete description of what you need to accomplish and your current script, we should be able to suggest proper alternatives.


FishMonger
Veteran / Moderator

Mar 22, 2009, 8:38 PM

Post #4 of 4 (1453 views)
Re: [pozvanete] Need help about preventing overloading a script! [In reply to] Can't Post

Never use '&' to call a sub unless you not only know about, but understand and want the side affects.

I'd say that you first need to fix and reduce the number of available modules and then use a dispatch table.

http://en.wikipedia.org/wiki/Dispatch_table

 
 


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

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