in reply to Runtime module use and sub definitions
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,
|
|---|