Modules in a required file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm have several scripts that share the same function, so I'm moving
that function to a separate script and using require in the parent

This function uses the CGI::Cookie module. Do I need to "use" this
module in each of the parent scripts, or can I only call it once in
the required script?

Re: Modules in a required file

Quoted text here. Click to load it

Consider making a proper module instead. It has several advantages.

Quoted text here. Click to load it

CGI::Cookie appears to be an OO module, so you need only 'require' or
'use' it once before you attempt to create your first object. For
modules that export functions, you need to 'use' them once per package,
so if your required file uses the same package as the file requiring it
a single 'use' will suffice. Modules that have lexical effect, like
'strict' and 'warnings', need to be used separately in every scope they
need to apply to, so don't forget the 'use warnings; use strict;' in the
required file.


Site Timeline