Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^3: dynamic loading modules

by fishmonger (Chaplain)
on Sep 03, 2012 at 16:23 UTC ( #991465=note: print w/replies, xml ) Need Help??

in reply to Re^2: dynamic loading modules
in thread dynamic loading modules

Unless I'm misunderstanding your goal, I don't see any reason why you can't use Module::Load or Module::Load::Conditional or a combination of both. Here's a simple test script which works for me.
#!/usr/bin/perl use strict; use warnings; use Module::Load; my $os = 'Yet Unknown'; if ( $^O =~ /MSWin/ ) { load 'Win32'; $os = Win32::GetOSName(); } print $os;
Output of my test: D:\perl>

Replies are listed 'Best First'.
Re^4: dynamic loading modules
by sdetweil (Sexton) on Sep 03, 2012 at 16:58 UTC
    thx.. that works, but I don't understand 'why'.. how does the compiler know NOT to require the Win32 module in this case, but in my existing source, with no explicit use statement it does?

    anyhow.. now I have the same problem with TieRegistry <code> use Win32::TieRegistry; $Registry->Open(keyname);

    the doc says 'new(keyname)' should work, and then there are a bunch of functions off the handle..

    but I get Autoload is deprecated. or open not found.

    then must be some easy, clear way to handle this. without having to know the internals of every package.

        well, that requires learning ANOTHER pile of function..

        but I have my answer.. SOMETHING tells the compiler things are different..

        load 'package' value = package::function(); vs use Package::function; value = Package::Function;
        and maybe its just my mis understanding
        the value = is the same. the use vs load is to tell the runtime how to resolve.
        'use' means compiled in to some internal table,
        'load' means dynamically added to the same table.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991465]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-04-20 23:07 GMT
Find Nodes?
    Voting Booth?