Re: Adding the use statements to a different file



vmalik@xxxxxxxxxxxxxxxxxxxx wrote:
Hi,

I have to write several perl scripts with a number of modules included.
Therefore, I have to type many "use" statements at the top of each script. Is
there a way to dump all these "use" statements in a different file and then just
include that file everytime I have to include these "use" statements?

I know that writing a module is a great way to do something like that, but
doesn't a module export variables and subroutines? How can I make a module
export "use" statements?

Perl has three distinct ways of separating content: modules, packages, and objects. Modules do not export variables and subroutines; packages do. Or to be specific, packages can export variables and subroutines to the main package.


You can use a module as a straight-forward include. Simply list the material you want and it will be including in the package where the 'use' command is.

In the main file:

use MyUseList;

Create a file called MyUseList.pm and add your list.

#!/usr/bin/perl

use strict;
use warnings;

# Your list goes here

1;  # Modules must return a non-false value
__END__


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
.



Relevant Pages

  • Re: Adding the use statements to a different file
    ... Quoting Shawn Corey: ... >> I have to write several perl scripts with a number of modules included. ... Modules do not export variables and subroutines; packages ...
    (perl.beginners)
  • Re: Win32::OLE packages
    ... Subject: Win32::OLE packages ... OLE Automation brings VisualBasic like scripting capabilities and offers powerful extensibility and the ability to control many Win32 applications from Perl scripts. ... Does anybody know which package in Win32:OLE will Freeze Panes and call Format Report method in excel document? ...
    (perl.beginners)
  • Re: best practice ... requires
    ... In main.cgi i have some other perl scripts that have subroutines ... $filebase = cwd; ... If you also import symbols from some.lib and the subroutines are in a separate package, it's better to require the library from the script that is using the subs. ...
    (comp.lang.perl.misc)
  • Re: .deb files arch independant?
    ... Some are (like perl scripts or documentation), ... itself or binary programs), so even though deb packages are called ... binary packages (in contrast to source packages) some of them can be ...
    (Debian-User)
  • Re: best practice ... requires
    ... I have a main cgi script ... ... In main.cgi i have some other perl scripts that have subroutines ... Yes, as already noted, package variables defined ... This applies to subroutines as well. ...
    (comp.lang.perl.misc)