Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: dynamic loading modules

by daxim (Chaplain)
on Sep 03, 2012 at 14:37 UTC ( #991444=note: print w/replies, xml ) Need Help??


in reply to dynamic loading modules

The symbol GetOSName is not defined at compile time, so move the conditional module loading into a BEGIN block.

Replies are listed 'Best First'.
Re^2: dynamic loading modules
by sdetweil (Sexton) on Sep 03, 2012 at 15:19 UTC
    thx.. I added this to my begin block
    if ($^O eq "MSWin32") { print ("begin\n"); my $win32 ="Win32.pm"; require $win32; import $win32 qw(GetOSName); }
    I get the print message fom my begin block code. and still call it
    my $os = GetOSName();
    and it still fails
    Undefined subroutine &main::GetOSName

      This is never going to work:

      my $win32 ="Win32.pm"; import $win32 qw(GetOSName);

      If there isn't already an import() in your current package, this will effectively become:

      'Win32.pm'->import( 'GetOSName' );

      Because there's no package called Win32.pm, nothing will get imported. You're better off writing:

      Win32->import( 'GetOSName' );

      ... or even:

      'Win32'->import( 'GetOSName' );
      The line calling GetOSName() should never be called on any system other than Windows. Fix the logic of your program.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991444]
help
Chatterbox?
[Corion]: Whee! Germanys Grand Central Airport (for Berlin, re-scheduled for the thrid or fourth time, to open now in 2018) has just fired their technical lead
[ambrus]: Corion: Is their budget estimate four times the initial estimate yet? Was the construction late by six months already three months after they started?
[marto]: I'll believe it when I see it. That's been due for many years now :P

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2017-02-23 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (345 votes). Check out past polls.