1. How to store routines in separate files:
#file shared1.pm:
use strict;
sub xxx1 ($\%\@@) # define xxx1 with prototype
{ blah blah;
return ...;
} # end sub xxx1
use Exporter(); @ISA=qw(Exporter);
@EXPORT = qw(xxx1); # exports name xxx1
-----------------
Now, in your main.pl program file, you may call subroutine defined in shared1.pm above:
use strict;
use shared1; # 'include' shared code
...
# call sub defined in shared1.pm
my $result = xxx1($arg1, %arg2, @arg3, $optarg1, $optarg2);
...
---------------------
2. In project this huge, I advise to use not only 'use strict' everywhere, you may want to learn how to do 'prototypes' as well. It will help you to detect (some) errors when wrong numbers or types of parameters are passed to subroutine. While on that, you can also learn to pass hashes as references.
Good luck on your long jourmey!
PMAS
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|