On Fri, 25 May 2007, Bill Schwanitz wrote:
> I am writing a perl script which I want to have platform independent.
> 
> The over-all scope of the script is to pull in an xml doc, parse it and
> do group membership lookups against a variety of back-end systems. I
> have currently coded ( and gotten working ) standard unix getent and
> lookups against windows via Win32::Ole.
> 
> I am trying to change the use to a require:
> 
> sub ResolveViaWin32 {
> (...)
>     BEGIN {
>       require Win32::OLE or die "failed to require Win32::OLE: $!\n";
>       import Win32::OLE 'in' or die "failed to import in: $!\n";
>     }
> (...)
> }
> 
> The require works, the import fails. My use ( use Win32::OLE 'in'; )
> works great.
> 
> Is there another way to accomplish this which I have just not found yet?

I suspect something with indirect object syntax going wrong.  Did you
try:

    Win32::OLE->import('in') or die;

Alternatively you could get rid of the import() call and always call
Win32::OLE::in() explicitly, though that is slightly ugly.

However, using a BEGIN block inside a function doesn't make a lot of sense,
as the block is evaluated at compile time, and the import will not be
lexically scoped to the function.  I would put the BEGIN block at file level,
together with the rest of your "use" statements:

    BEGIN {
        return unless $^O eq "MSWin32";
        require Win32::OLE;
        Win32::OLE->import('in');
    }

Cheers,
-Jan

_______________________________________________
Perl-Win32-Admin mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to