in reply to Runtime module use and sub definitions

If you can find a different way to initalize your sub, you can get rid of the string eval, which is my only objection.
eval { require module1; module1->import(); } *bar = sub { print "Win32\n" };
You may need a forward declaration, as this is untested. Otherwise, that's probably the first thing I'd try. (It's simple.)

Replies are listed 'Best First'.
(RhetTbull) Re: Re: Runtime module use and sub definitions
by RhetTbull (Curate) on Apr 03, 2002 at 21:21 UTC
    I like that much better than the string eval. I tried this and it seems to work fine:
    #!/usr/bin/perl use strict; use warnings; if ($^O eq 'MSWin32') { eval { require Win32::OLE; Win32::OLE->import; }; *bar = sub { print "Win32\n" }; } else { *bar = sub { print "Not Win32\n" }; } #later in the program... #we don't care what OS is running -- implementation details are hidden bar();
      You can leave out that eval completely, unless you intend to check for errors during the require and import statements.