Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Runtime module use and sub definitions

by chromatic (Archbishop)
on Apr 03, 2002 at 20:48 UTC ( [id://156434]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://156434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-24 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found