Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: How to create a reusable routine ?

by bar10der (Beadle)
on Apr 02, 2004 at 13:21 UTC ( #341960=note: print w/replies, xml ) Need Help??

in reply to How to create a reusable routine ?


I think Exporter will do the trick for me. Since I am new to perl, please ignore my little ignorance, I am bit confused regarding where should I place my (intented name of the package!) Ideally I'd like to keep it under cgi-bin/lib dir, no prob in that but where I am stuck is how do I call this routine from other directories under cgi-bin? So to give an example, if I am writing another script under cgi-bin/monthSale/ and want to call in, how do I do this?

Replies are listed 'Best First'.
Re: Re: How to create a reusable routine ?
by snowcrash (Friar) on Apr 02, 2004 at 14:06 UTC
    There's a special variable called @INC, it contains the paths in which perl looks for modules when you use one.
    An easy way to add directiories to @INC is the lib module.
    Just put these lines into the module/script that needs to call subroutines in
    use lib '/path/to/your/module_dir'; # can be relative, too use;
Re: Re: How to create a reusable routine ?
by bronto (Priest) on Apr 02, 2004 at 13:55 UTC

    Well, I assume that you are calling your script, and not .pm. First of all, I strongly descourage you to put your libraries in any place where a web user can get. Said that, suppose you are putting your in /usr/lib/cgi. Then you'll want to start your script with something such:

    #!/usr/bin/perl use strict ; # ...and... use warnings ; # always! # let your cgi find in /usr/lib/cgi... use lib '/usr/lib/cgi' ; # ...and you are safe ;-) use # your CGI goes here :-)

    I hope this helps


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://341960]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2021-09-19 15:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found