you could also use an init sub, where you require the modules you need, and set some variables to the different subs...
note: I have not tested this code, and I haven't done any cross-platform scripting that requires something like this, I just remembered seeing this technique in Perl For System Administration by David N. Blank-Edelman (ORA).
sub Init {
use Common::Module;
my ($common_var01, $common_var02) = ($foo, $bar);
if ($^0 eq "MSWin32") {
require Win32::Baz;
require Win32::Quux;
common_sub01 = "common_sub01_nt";
common_sub02 = "common_sub02_nt";
}
else {
require Foo;
common_sub01 = "common_sub01_unix";
common_sub02 = "common_sub02_unix";
}
}
sub common_sub01_nt {
...
}
sub common_sub01_unix {
...
}
# main program
# (where we call the subs)
&$common_sub01($foo, $bar) if $foobar;
hope it helps,
-
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.
|