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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
eval "use Win32::File";

You can just use 'require' instead if you just want it to happen at runtime.

require Win32::File;

I even go as far as using 'require' more than I use 'use' these days for modules it seems. You lose the questionable benefits of import(), but you're not taking advantage of import() in this example anyway. As chromatic already pointed out, you'll want to avoid barewords referring to code that hasn't been compiled yet, addressing them as functions by appending '()' will work fine. No need for the '&'.

In my experience, dynamically compiling during runtime is great, especially when loading a large number of modules over an NFS mount. Only loading what's needed as its needed will improve response time, reducing the initial compilation time. But compilation errors in the middle of execution can be bad, and that's why you really want the 'eval'. Not just to make use work at runtime, but to make sure runtime compilation errors are caught and handled in a user-friendly way.

This is like what I do in my Abstract Factories:

if( ! eval "require ${package}" ) ) { throw E_BadSubClass( "package '${package}' not found or failed + to compile.\n" . $@ . "\n" ); }


In reply to Re: including modules during runtime and dealing with OS specific (constants) code block by armstd
in thread including modules during runtime and dealing with OS specific (constants) code block by periferral

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [marto]: time for coffee

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (8)
    As of 2018-05-21 08:16 GMT
    Find Nodes?
      Voting Booth?